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