1 /* Test volatile access to unaligned field. */ 2 /* { dg-do run } */ 3 /* { dg-options "-fstrict-volatile-bitfields" } */ 4 5 extern void abort (void); 6 7 #define test_type unsigned long long 8 #define MAGIC 0x102030405060708ull 9 10 typedef struct s{ 11 unsigned char Prefix; 12 test_type Type; 13 }__attribute((__packed__)) ss; 14 15 volatile ss v; 16 ss g; 17 18 void __attribute__((noinline)) foo(test_type u)19foo (test_type u) 20 { 21 v.Type = u; 22 } 23 24 test_type __attribute__((noinline)) bar(void)25bar (void) 26 { 27 return v.Type; 28 } 29 main()30int main() 31 { 32 test_type temp; 33 foo(MAGIC); 34 __builtin_memcpy(&g, (void *)&v, sizeof(g)); 35 if (g.Type != MAGIC) 36 abort (); 37 38 g.Type = MAGIC; 39 __builtin_memcpy((void *)&v, &g, sizeof(v)); 40 temp = bar(); 41 if (temp != MAGIC) 42 abort (); 43 return 0; 44 } 45