From patchwork Tue May 7 15:54:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1932549 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Q7W2wpXD; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VYjWk2txHz1ydW for ; Wed, 8 May 2024 01:54:26 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 46235384AB64 for ; Tue, 7 May 2024 15:54:24 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 498E0384B06A for ; Tue, 7 May 2024 15:54:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 498E0384B06A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 498E0384B06A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715097248; cv=none; b=uApTf+FPoHMiXwAlKWu2tHfXTcVInImhYM3O3P3zVdFNbrXSJNJFouOCA5jQdXFwkGCHqo8YOgzdQYQB8ciswyd/4wLM/IG1cUvkHsWFi9RFR8GWEiUHxDKkzUTc9ih0Y5fJNlv6/a2ZyOtSCu8z2ZLhemx91Kn7cLhJ/8F5jFU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715097248; c=relaxed/simple; bh=X4FHF+KAkUCaew8Thzd4+6i0JJ53vGQs8YjUlFiqQW8=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=p6zzSxoaGAMVLTtHcLoaddYTgL2Qd+mCOMZoi9um3gymjzpNfBws8oF5zWv13qqlTbosd5fx4wNJJbPdfIRv0A63ilpoiLk8Xsry6HyWg4BQ6EISvk86QCpFfTeHe6eCAPprd7YtYlbDpsfEm+//3bERTrCt8yvl7y3uBdyzsmQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715097246; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=Yp1sI616sDt47sMD9F+nbR9i5R0enoEhADhK20s39b0=; b=Q7W2wpXDFqnPXbNUSaLIbrOn0afImlbJrjKX8TYKuurSyQHLMp8xTQSOUQxh2DAq2xzXKn WF/1N0bhgZzcwCbOFQVrqdA3uV2Te10TG+IJ3ovG/1o36QhjB1NW0fiDVCfXFroD0nnzi6 u08Sw2+02mL/878aYnl7/QiSkxtsecI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-435-zOsB7RcUOHizmx0Ili6M0Q-1; Tue, 07 May 2024 11:54:04 -0400 X-MC-Unique: zOsB7RcUOHizmx0Ili6M0Q-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 22362101A553; Tue, 7 May 2024 15:54:04 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.64]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DB5543C27; Tue, 7 May 2024 15:54:03 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 447Fs2OA2351857 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 7 May 2024 17:54:02 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 447Fs18i2351856; Tue, 7 May 2024 17:54:01 +0200 Date: Tue, 7 May 2024 17:54:01 +0200 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-inline: Remove .ASAN_MARK calls when inlining functions into no_sanitize callers [PR114956] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Hi! In r9-5742 we've started allowing to inline always_inline functions into functions which have disabled e.g. address sanitization even when the always_inline function is implicitly from command line options sanitized. This mostly works fine because most of the asan instrumentation is done only late after ipa, but as the following testcase the .ASAN_MARK ifn calls gimplifier adds can result in ICEs. Fixed by dropping those during inlining, similarly to how we drop .TSAN_FUNC_EXIT calls. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-05-07 Jakub Jelinek PR sanitizer/114956 * tree-inline.cc: Include asan.h. (copy_bb): Remove also .ASAN_MARK calls if id->dst_fn has asan/hwasan sanitization disabled. * gcc.dg/asan/pr114956.c: New test. Jakub --- gcc/tree-inline.cc.jj 2024-05-03 09:44:21.199055899 +0200 +++ gcc/tree-inline.cc 2024-05-06 10:45:37.231349328 +0200 @@ -65,6 +65,7 @@ along with GCC; see the file COPYING3. #include "symbol-summary.h" #include "symtab-thunks.h" #include "symtab-clones.h" +#include "asan.h" /* I'm not real happy about this, but we need to handle gimple and non-gimple trees. */ @@ -2226,13 +2227,26 @@ copy_bb (copy_body_data *id, basic_block } else if (call_stmt && id->call_stmt - && gimple_call_internal_p (stmt) - && gimple_call_internal_fn (stmt) == IFN_TSAN_FUNC_EXIT) - { - /* Drop TSAN_FUNC_EXIT () internal calls during inlining. */ - gsi_remove (©_gsi, false); - continue; - } + && gimple_call_internal_p (stmt)) + switch (gimple_call_internal_fn (stmt)) + { + case IFN_TSAN_FUNC_EXIT: + /* Drop .TSAN_FUNC_EXIT () internal calls during inlining. */ + gsi_remove (©_gsi, false); + continue; + case IFN_ASAN_MARK: + /* Drop .ASAN_MARK internal calls during inlining into + no_sanitize functions. */ + if (!sanitize_flags_p (SANITIZE_ADDRESS, id->dst_fn) + && !sanitize_flags_p (SANITIZE_HWADDRESS, id->dst_fn)) + { + gsi_remove (©_gsi, false); + continue; + } + break; + default: + break; + } /* Statements produced by inlining can be unfolded, especially when we constant propagated some operands. We can't fold --- gcc/testsuite/gcc.dg/asan/pr114956.c.jj 2024-05-06 10:54:52.601892840 +0200 +++ gcc/testsuite/gcc.dg/asan/pr114956.c 2024-05-06 10:54:33.920143734 +0200 @@ -0,0 +1,26 @@ +/* PR sanitizer/114956 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fsanitize=address,null" } */ + +int **a; +void qux (int *); + +__attribute__((always_inline)) static inline int * +foo (void) +{ + int b[1]; + qux (b); + return a[1]; +} + +__attribute__((no_sanitize_address)) void +bar (void) +{ + *a = foo (); +} + +void +baz (void) +{ + bar (); +}