From: Stefan Schulze Frielinghaus <[email protected]>

On s390 bit-fields are layed out from left-to-right.  Therefore, struct
member c starts 7+2+6+3 bits from the left aka the most significant bit.
The assignment to f.e only writes a single byte but the struct member c
crosses two bytes.  Using index 3 and assigning 7 to f.e results in only
writing a single bit of f.bf.c which is set to 0 which means the whole
member stays 0.  A probably more interesting index is 2 which renders
f.bf.c equal to 14 in the end.

gcc/testsuite/ChangeLog:

        * gcc.dg/torture/pr126650.c: Fix index and expected value for
        s390 where bit fields are layed out from left-to-right.
---
 Tested on s390x-linux and x86_64-linux.

 gcc/testsuite/gcc.dg/torture/pr126650.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr126650.c 
b/gcc/testsuite/gcc.dg/torture/pr126650.c
index 166705d9cfe..f9997b16f2b 100644
--- a/gcc/testsuite/gcc.dg/torture/pr126650.c
+++ b/gcc/testsuite/gcc.dg/torture/pr126650.c
@@ -1,5 +1,13 @@
 /* { dg-do run } */
 
+#if __s390__
+# define IDX 2
+# define VAL 14
+#else
+# define IDX 3
+# define VAL -64
+#endif
+
 #include <stdarg.h>
 #include <stdlib.h>
 
@@ -10,7 +18,7 @@ void __attribute__((noipa)) foo (int n, ...)
   va_list list;
   va_start (list, n);
   int val = va_arg (list, int);
-  if (val != -64)
+  if (val != VAL)
     abort ();
   va_end (list);
 }
@@ -30,6 +38,6 @@ int main()
     char e[4];
   } f;
   f.d = a;
-  f.e[3] = 7;
+  f.e[IDX] = 7;
   foo (1, f.bf.c);
 }
-- 
2.54.0

Reply via email to