Hi! On Tue, Jul 01, 2025 at 05:16:45PM +0200, Jakub Jelinek wrote: > This test seems to fail when testing with > RUNTESTFLAGS="--target_board=unix/'{,-fstack-protector-strong}'" > on power10.
Please mention near the start of the commit message (like, in the subject already!) that the testcase did UB, and this patch fixes it? > 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). Yup. > 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. Testcases do not always catch issues they were not designed for :-) > 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. > > Tested on powerpc64le-linux both without and with -fstack-protector-strong, > ok for trunk and 15.2/14.4? Okay everywhere (with a better commit message). Thanks! Segher > 2025-07-01 Jakub Jelinek <ja...@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.jj > 2023-06-03 15:32:05.230399713 +0200 > +++ gcc/testsuite/gcc.target/powerpc/builtin_altivec_tr_stxvr_runnable.c > 2025-07-01 17:03:03.026845771 +0200 > @@ -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 = ≻ > - 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 > > Jakub