1 /* PR middle-end/51782 */ 2 /* { dg-do run } */ 3 /* { dg-options { "-std=gnu99" } } */ 4 5 #include <stdlib.h> 6 7 #ifndef __FLASH 8 #define __flash /* empty */ 9 #endif 10 11 struct R { char r; }; 12 struct RGB { char r,g,b; }; 13 14 __flash const struct R r1 = { 12 }; 15 __flash const struct RGB r3 = { 23, 56, 78 }; 16 17 char __attribute__((noinline,noclone)) read1_bug(const __flash struct R * s)18read1_bug (const __flash struct R *s) 19 { 20 struct R t = *s; 21 return t.r; 22 } 23 24 char __attribute__((noinline,noclone)) read1_ok(const __flash struct R * s)25read1_ok (const __flash struct R *s) 26 { 27 return s->r; 28 } 29 30 char __attribute__((noinline,noclone)) read3_bug(const __flash struct RGB * s)31read3_bug (const __flash struct RGB *s) 32 { 33 struct RGB t = *s; 34 return t.r + t.g + t.b; 35 } 36 37 char __attribute__((noinline,noclone)) read3_ok(const __flash struct RGB * s)38read3_ok (const __flash struct RGB *s) 39 { 40 return s->r + s->g + s->b; 41 } 42 43 __flash const struct R * volatile p1 = &r1; 44 __flash const struct RGB * volatile p3 = &r3; 45 main(void)46int main (void) 47 { 48 if (read1_bug (p1) != read1_ok (p1)) 49 abort(); 50 51 if (read3_bug (p3) != read3_ok (p3)) 52 abort(); 53 54 exit (0); 55 } 56