]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
testsuite: Fix up c-c++-common/asan/asan-stack-small.c test
authorJakub Jelinek <jakub@redhat.com>
Sat, 15 Nov 2025 15:06:05 +0000 (16:06 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Sat, 15 Nov 2025 15:06:05 +0000 (16:06 +0100)
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.

2025-11-15  Jakub Jelinek  <jakub@redhat.com>

* 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

index 11a56b8db4cbd94cfc7bdf1fb24f2c4600caff40..d045406c9fb1f7920546807094b98ab60a8c3a72 100644 (file)
@@ -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;
 }