Debian Codegraph @

gcc/testsuite/gcc.dg/field-merge-11.c

raw
1 /* { dg-do run } */
2 /* { dg-options "-O" } */
3
4 /* Check that narrowing casts aren't ignored, and that same-field tests at
5 different widths aren't misoptimized. */
6
7 struct s {
8 short a;
9 unsigned short b;
10 int c;
11 } __attribute__ ((aligned (4)));
12
13 struct s p = {
14 (short)(unsigned short)42,
15 (short)(unsigned short)(0xef1 - 0x1000),
16 (int)(unsigned int)0x12345678
17 };
18
19 void f (void) {
20 if (0
21 || (p.a & 0xcc) != 8
22 || p.a != 42
23 || (int)(signed char)p.b != (int)(signed char)(0xef1 - 0x1000)
24 || (unsigned)(unsigned char)p.b != (unsigned)(unsigned char)(0xef1 - 0x1000)
25 || (unsigned)p.b != (unsigned short)(0xef1 - 0x1000)
26 || (int)(short)p.b != (int)(short)(unsigned short)(0xef1 - 0x1000)
27 || (long)(unsigned char)(p.c >> 8) != (long)(unsigned char)0x123456
28 || p.c != (int)(unsigned int)0x12345678
29 )
30 __builtin_abort ();
31 }
32
33 int main () {
34 f ();
35 return 0;
36 }