]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
testsuite: Fix up gcc.target/powerpc/builtin_altivec_tr_stxvr_runnable.c test (test...
authorJakub Jelinek <jakub@redhat.com>
Tue, 1 Jul 2025 17:37:39 +0000 (19:37 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 1 Jul 2025 17:37:39 +0000 (19:37 +0200)
In my reading of the test and the instructions emitted by the
builtins, it invokes UB 4 times, each time overwriting one byte
after some variable (sc, then ss, then si and then sll).
If we are lucky, like at -O0 -mcpu=power10, there is just padding
there or something that doesn't make the tests fail, if unlucky
like with -O0 -mcpu=power10 -fstack-protector-strong,
&sc + 1 == &expected_sc
and so it overwrites the expected_sc variable.
The test fails when testing with
RUNTESTFLAGS="--target_board=unix/'{,-fstack-protector-strong}'"
on power10.

The following patch fixes that by using arrays of 2 elements, so that
the overwriting of 1 byte happens to the part of the same variable.

2025-07-01  Jakub Jelinek  <jakub@redhat.com>

PR testsuite/120919
* gcc.target/powerpc/builtin_altivec_tr_stxvr_runnable.c (main): Change
sc, ss, si and sll vars from scalars to arrays of 2 elements,
initialize and test just the first one though.

gcc/testsuite/gcc.target/powerpc/builtin_altivec_tr_stxvr_runnable.c

index 4b90437973275ac9c6d60aeeb5354c456bad08bd..fab7a529e39c0e798e0799d252584d53e90d3f08 100644 (file)
@@ -27,10 +27,10 @@ int
 main () {
   int i;
   signed long sl;
-  signed char sc, expected_sc;
-  signed short ss, expected_ss;
-  signed int si, expected_si;
-  signed long long int sll, expected_sll;
+  signed char sc[2], expected_sc;
+  signed short ss[2], expected_ss;
+  signed int si[2], expected_si;
+  signed long long int sll[2], expected_sll;
   signed char *psc;
   signed short *pss;
   signed int *psi;
@@ -41,56 +41,56 @@ main () {
   printf("Data to store [%d] = 0x%llx %llx\n", i, val.ull[1], val.ull[0]);
 #endif
 
-  psc = &sc;
-  pss = &ss;
-  psi = &si;
-  psll = &sll;
+  psc = &sc[0];
+  pss = &ss[0];
+  psi = &si[0];
+  psll = &sll[0];
 
   sl = 1;
-  sc = 0xA1;
+  sc[0] = 0xA1;
   expected_sc = 0xA1;
   __builtin_altivec_tr_stxvrbx (store_data, sl, psc);
 
-  if (expected_sc != sc & 0xFF)
+  if (expected_sc != sc[0] & 0xFF)
 #if DEBUG
     printf(" ERROR: Signed char = 0x%x doesn't match expected value 0x%x\n",
-          sc & 0xFF, expected_sc);
+          sc[0] & 0xFF, expected_sc);
 #else
     abort();
 #endif
 
-  ss = 0x52;
+  ss[0] = 0x52;
   expected_ss = 0x1752;
   __builtin_altivec_tr_stxvrhx (store_data, sl, pss);
 
-  if (expected_ss != ss & 0xFFFF)
+  if (expected_ss != ss[0] & 0xFFFF)
 #if DEBUG
     printf(" ERROR: Signed short = 0x%x doesn't match expected value 0x%x\n",
-          ss, expected_ss) & 0xFFFF;
+          ss[0], expected_ss) & 0xFFFF;
 #else
     abort();
 #endif
 
-  si = 0x21;
+  si[0] = 0x21;
   expected_si = 0x54321721;
   __builtin_altivec_tr_stxvrwx (store_data, sl, psi);
 
-  if (expected_si != si)
+  if (expected_si != si[0])
 #if DEBUG
     printf(" ERROR: Signed int = 0x%x doesn't match expected value 0x%x\n",
-          si, expected_si);
+          si[0], expected_si);
 #else
     abort();
 #endif
 
-  sll = 0x12FFULL;
+  sll[0] = 0x12FFULL;
   expected_sll = 0xdcba9876543217FF;
   __builtin_altivec_tr_stxvrdx (store_data, sl, psll);
 
-  if (expected_sll != sll)
+  if (expected_sll != sll[0])
 #if DEBUG
     printf(" ERROR: Signed long long int = 0x%llx doesn't match expected value 0x%llx\n",
-          sll, expected_sll);
+          sll[0], expected_sll);
 #else
     abort();
 #endif