public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-9324] asan: Handle poly-int sizes in ASAN_MARK [PR97696]
@ 2024-03-05 19:48 Richard Sandiford
  0 siblings, 0 replies; only message in thread
From: Richard Sandiford @ 2024-03-05 19:48 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:fca6f6fddb22b8665e840f455a7d0318d4575227

commit r14-9324-gfca6f6fddb22b8665e840f455a7d0318d4575227
Author: Richard Sandiford <richard.sandiford@arm.com>
Date:   Tue Mar 5 19:48:25 2024 +0000

    asan: Handle poly-int sizes in ASAN_MARK [PR97696]
    
    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.
    
    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.

Diff:
---
 gcc/asan.cc                                    |  9 ++++----
 gcc/testsuite/gcc.target/aarch64/sve/pr97696.c | 29 ++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 5 deletions(-)

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..8b7de18a07d
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/sve/pr97696.c
@@ -0,0 +1,29 @@
+/* { dg-skip-if "" { no_fsanitize_address } } */
+/* { dg-options "-fsanitize=address -fsanitize-address-use-after-scope" } */
+
+#include <arm_sve.h>
+
+__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;
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-03-05 19:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-05 19:48 [gcc r14-9324] asan: Handle poly-int sizes in ASAN_MARK [PR97696] Richard Sandiford

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).