From patchwork Tue Mar 5 18:03:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 1908409 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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 4Tq3NR2Bk6z1yX3 for ; Wed, 6 Mar 2024 05:04:05 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7CE51385842F for ; Tue, 5 Mar 2024 18:04:03 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 63E693858D20 for ; Tue, 5 Mar 2024 18:03:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 63E693858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 63E693858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709661825; cv=none; b=NxqA9zP1z66Q1/qgrD7FPJ4GGUI9JnUNi26uc/XWfvNogkYIRb11uyra2ZTiRMoqcVfv1blRrQ3FmHsW9mxlmJh0ZsDnTWU6u/0Mql0nGrCPXzJ7Y6B3qrG2lZb8udWVB/8TCiJsB0LoypNb8Sdq3q+rDID1N3wQN8g5/3Lgwr8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709661825; c=relaxed/simple; bh=CZP7PTK9IQOjuVeFxfBs+noRLvbr0FnimGDhXSSpRnQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=c2PKNWO+6iTLAEkbHWZ4JdE5Il5zVGr2STvMpAVpR3GD/up/a6eFOniWQje5LaFz1j5Vrs6dDyghwe5c/FxIA1IZlMbiC2vEuRNYap0GM75aev9bkyQaYjGmhVUC7SrLTdUz3rzIKzIgeyusJFoywZSNVMj7UQo9oOsbi+k6mrc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D452A1FB for ; Tue, 5 Mar 2024 10:04:19 -0800 (PST) Received: from localhost (e121540-lin.manchester.arm.com [10.32.110.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C03CF3F73F for ; Tue, 5 Mar 2024 10:03:42 -0800 (PST) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: [PATCH] asan: Handle poly-int sizes in ASAN_MARK [PR97696] Date: Tue, 05 Mar 2024 18:03:41 +0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Spam-Status: No, score=-20.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org This patch makes the expansion of IFN_ASAN_MARK let through poly-int-sized objects. The expansion itself was already generic enough, but the tests for the fast path were too strict. Bootstrapped & regression tested on aarch64-linux-gnu. Is this OK for trunk now, or should it wait for GCC 15? I'm not sure that it's technically a regression, in the sense that we previously accepted the testcase, but rejecting with an ICE is arguably worse than "sorry, can't do that". And as noted in the PR, this bug is breaking numpy builds. Richard gcc/ PR sanitizer/97696 * asan.cc (asan_expand_mark_ifn): Allow the length to be a poly_int. gcc/testsuite/ PR sanitizer/97696 * gcc.target/aarch64/sve/pr97696.c: New test. --- gcc/asan.cc | 9 +++--- .../gcc.target/aarch64/sve/pr97696.c | 28 +++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/pr97696.c diff --git a/gcc/asan.cc b/gcc/asan.cc index 0fd7dd1f3ed..d621ec9c323 100644 --- a/gcc/asan.cc +++ b/gcc/asan.cc @@ -3795,9 +3795,7 @@ asan_expand_mark_ifn (gimple_stmt_iterator *iter) } tree len = gimple_call_arg (g, 2); - gcc_assert (tree_fits_shwi_p (len)); - unsigned HOST_WIDE_INT size_in_bytes = tree_to_shwi (len); - gcc_assert (size_in_bytes); + gcc_assert (poly_int_tree_p (len)); g = gimple_build_assign (make_ssa_name (pointer_sized_int_node), NOP_EXPR, base); @@ -3806,9 +3804,10 @@ asan_expand_mark_ifn (gimple_stmt_iterator *iter) tree base_addr = gimple_assign_lhs (g); /* Generate direct emission if size_in_bytes is small. */ - if (size_in_bytes - <= (unsigned)param_use_after_scope_direct_emission_threshold) + unsigned threshold = param_use_after_scope_direct_emission_threshold; + if (tree_fits_uhwi_p (len) && tree_to_uhwi (len) <= threshold) { + unsigned HOST_WIDE_INT size_in_bytes = tree_to_uhwi (len); const unsigned HOST_WIDE_INT shadow_size = shadow_mem_size (size_in_bytes); const unsigned int shadow_align diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pr97696.c b/gcc/testsuite/gcc.target/aarch64/sve/pr97696.c new file mode 100644 index 00000000000..f533d9efc02 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/pr97696.c @@ -0,0 +1,28 @@ +/* { dg-options "-fsanitize=address -fsanitize-address-use-after-scope" } */ + +#include + +__attribute__((noinline, noclone)) int +foo (char *a) +{ + int i, j = 0; + asm volatile ("" : "+r" (a) : : "memory"); + for (i = 0; i < 12; i++) + j += a[i]; + return j; +} + +int +main () +{ + int i, j = 0; + for (i = 0; i < 4; i++) + { + char a[12]; + __SVInt8_t freq; + __builtin_bcmp (&freq, a, 10); + __builtin_memset (a, 0, sizeof (a)); + j += foo (a); + } + return j; +}