1 /* PR tree-optimization/53265 */
2 /* { dg-do compile } */
3 /* { dg-options "-O2 -Wall" } */
4
5 void bar (void *);
6 int baz (int);
7
8 void
fn1(void)9 fn1 (void)
10 {
11 unsigned int a[128];
12 int i;
13
14 for (i = 0; i < 128; ++i) /* { dg-message "note: containing loop" } */
15 a[i] = i * 0x02000001; /* { dg-warning "invokes undefined behavior" } */
16 bar (a);
17 }
18
19 void
fn2(void)20 fn2 (void)
21 {
22 unsigned long long a[128];
23 int i;
24
25 for (i = 0; i < 128; i++) /* { dg-message "note: containing loop" } */
26 a[i] = (i + 1LL) * 0x0123456789ABCDEFLL; /* { dg-warning "invokes undefined behavior" } */
27 bar (a);
28 }
29
30 void
fn3(void)31 fn3 (void)
32 {
33 unsigned char a[16], b[16], c[16];
34 int i;
35
36 bar (b);
37 for (i = 0; i < (int) (sizeof (a) / sizeof (a[0])); i++) /* { dg-message "note: containing loop" } */
38 {
39 c[i + 8] = b[i]; /* { dg-warning "invokes undefined behavior" } */
40 a[i + 8] = b[i + 8];
41 }
42 bar (a);
43 bar (c);
44 }
45
46 void
fn4(void)47 fn4 (void)
48 {
49 unsigned int *a[32], *o, i;
50
51 bar (a);
52 for (i = 0; i <= sizeof (a) / sizeof (a[0]); i++) /* { dg-message "note: containing loop" "" { xfail *-*-* } } */
53 {
54 o = a[i]; /* { dg-warning "invokes undefined behavior" "" { xfail *-*-* } } */
55 bar (o);
56 }
57 }
58
59 void
fn5(void)60 fn5 (void)
61 {
62 unsigned short a[23940];
63 unsigned int b[1140];
64 int j;
65
66 bar (b);
67 for (j = 0; j < 1140; j++) /* { dg-message "note: containing loop" } */
68 a[23940 + j - 950] = b[j]; /* { dg-warning "invokes undefined behavior" } */
69 bar (a);
70 }
71
72 void
fn6(void)73 fn6 (void)
74 {
75 double a[4][3], b[12];
76 int i;
77 bar (b);
78 for (i = 0; i < 12; i++) /* { dg-message "note: containing loop" } */
79 a[0][i] = b[i] / 10000.0; /* { dg-warning "invokes undefined behavior" } */
80 bar (a);
81 }
82
83 void
fn7(void)84 fn7 (void)
85 {
86 int a[16], b, c;
87 bar (a);
88 for (b = a[c = 0]; c < 16; b = a[++c]) /* { dg-warning "invokes undefined behavior" "" { xfail *-*-* } } */
89 baz (b);
90 }
91
92 /* { dg-message "note: containing loop" "" { xfail *-*-* } 88 } */
93
94 const void *va, *vb, *vc, *vd, *ve;
95 const void *vf[4];
96 void
fn8(void)97 fn8 (void)
98 {
99 unsigned long i;
100 vf[0] = va; vf[1] = vb; vf[2] = vc; vf[3] = vd;
101 for (i = 0; i < (sizeof (vf) / sizeof (vf[0])); i++)
102 if (!vf[i])
103 vf[i] = ve;
104 }
105
106 int wa, wb[53][5], wc[53][5];
107
108 void
fn9(void)109 fn9 (void)
110 {
111 int i, j, k;
112 for (i = 0; i < 53; i++)
113 for (j = 16 / (((wa & 1) != 0) ? 8 : 4); j > 0; j--)
114 {
115 int d = 1;
116 if (wb[i][j] == 0 || wc[i][1] != 0)
117 continue;
118 for (k = 0; k < j; k++)
119 if (wc[i + k][1])
120 {
121 d = 0;
122 break;
123 }
124 if (!d)
125 continue;
126 wc[i][j] = baz (0);
127 }
128 }
129
130 int xa[18];
131
132 void
fn10(void)133 fn10 (void)
134 {
135 int i;
136 for (i = 16; i < 32; i++) /* { dg-message "note: containing loop" } */
137 xa[i] = 26; /* { dg-warning "invokes undefined behavior" } */
138 }
139
140 __attribute__((noinline)) static void
fn11(int x)141 fn11 (int x)
142 {
143 int i = 1;
144 if (x > 1)
145 do
146 baz (i);
147 while (++i != x); /* { dg-bogus "invokes undefined behavior" } */
148 }
149
150 void
fn12(void)151 fn12 (void)
152 {
153 fn11 (1);
154 fn11 (1);
155 fn11 (1);
156 }
157