Hi!

Here is a fix for the test I've talked about today in the libsanitizer
update mail.

The test relied on a coming before b coming before c, all with 32 byte
distances, but gcc can actually emit them in the exact opposite order
or some other one.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2025-11-14  Jakub Jelinek  <[email protected]>

        * c-c++-common/asan/asan-stack-small.c (pa, pb, pc): Make these
        vars volatile.
        (uintptr_t): New typedef.
        (main): Use access of b using pa pointer with offset depending on
        how exactly the 3 variables are laid out in the frame.

--- gcc/testsuite/c-c++-common/asan/asan-stack-small.c.jj       2020-01-14 
20:02:46.644611916 +0100
+++ gcc/testsuite/c-c++-common/asan/asan-stack-small.c  2025-11-14 
12:14:46.078840290 +0100
@@ -1,8 +1,9 @@
 /* { dg-do run } */
 
-char *pa;
-char *pb;
-char *pc;
+char *volatile pa;
+char *volatile pb;
+char *volatile pc;
+typedef __UINTPTR_TYPE__ uintptr_t;
 
 void access (volatile char *ptr)
 {
@@ -22,7 +23,14 @@ int main (int argc, char **argv)
   access (pb);
   access (pc);
   // access 'b' here
-  access (pa + 32);
+  if ((uintptr_t) pb == (uintptr_t) pa + 32)
+    access (pa + 32);
+  else if ((uintptr_t) pb == (uintptr_t) pa - 32)
+    access (pa - 32);
+  else if ((uintptr_t) pb == (uintptr_t) pa + 64)
+    access (pa + 64);
+  else if ((uintptr_t) pb == (uintptr_t) pa - 64)
+    access (pa - 64);
 
   return 0;
 }

        Jakub

Reply via email to