Merge from mainline (160224:163495).
[official-gcc/graphite-test-results.git] / gcc / testsuite / gcc.dg / pr36902.c
blob43a2d14f981f18ad252a806a4cda3bf69e28f786
1 /* PR middle-end/36902 Array bound warning with dead code after optimization */
2 /* { dg-do compile } */
3 /* { dg-options "-O2 -Warray-bounds -Wall -Wextra" } */
4 typedef unsigned char __u8;
5 typedef unsigned short __u16;
7 static inline unsigned char *
8 foo(unsigned char * to, const unsigned char * from, int n)
10 switch ( n )
12 case 3:
13 *to = *from;
14 break;
15 case 5:
16 to[4] = from [4];
17 break;
19 return to;
22 struct {
23 int size_of_select;
24 unsigned char pcr_select[4];
25 } sel;
27 int bar(void)
29 static unsigned char buf[64];
31 sel.size_of_select = 3;
32 foo(buf, sel.pcr_select, sel.size_of_select);
34 return 1;
38 static inline unsigned char *
39 foo2(unsigned char * to, const unsigned char * from, int n)
41 switch ( n )
43 case 3:
44 *to = *from;
45 break;
46 case 5:
47 to[4] = from [4]; /* { dg-warning "array subscript is above array bounds" } */
48 break;
50 return to;
53 int baz(void)
55 static unsigned char buf[64];
57 sel.size_of_select = 5;
58 foo2(buf, sel.pcr_select, sel.size_of_select);
60 return 1;