1 /* PR c/64279 */
2 /* { dg-do compile } */
3 /* { dg-options "-Wduplicated-branches -O2" } */
4
5 extern void foo (int);
6 extern int g;
7 extern int a[10];
8
9 int
10 f (int i, int *p)
11 {
12 const int j = 0;
13 if (j == 0)
14 {
15 if (i > 10) /* { dg-warning "this condition has identical branches" } */
16 /* Optimizers can figure out that this is 1. */
17 *p = j * 2 + 1;
18 else
19 *p = 1;
20 }
21
22 if (i)
23 ;
24 else
25 ;
26
27 if (i == 0) /* { dg-warning "this condition has identical branches" } */
28 return 0;
29 else
30 return 0;
31
32 if (i == 1) /* { dg-warning "this condition has identical branches" } */
33 {
34 g = 10;
35 }
36 else
37 {
38 g = 10;
39 }
40
41 const char *s;
42 if (i == 2) /* { dg-warning "this condition has identical branches" } */
43 s = "foo";
44 else
45 s = "foo";
46
47 if (i == 3) /* { dg-warning "this condition has identical branches" } */
48 g = a[i];
49 else
50 g = a[i];
51
52 if (i == 4) /* { dg-warning "this condition has identical branches" } */
53 return i ? 1 : g;
54 else
55 return i ? 1 : g;
56
57 if (i == 5) /* { dg-warning "this condition has identical branches" } */
58 {
59 {
60 {
61 {
62 g++;
63 }
64 }
65 }
66 }
67 else
68 {
69 {
70 {
71 {
72 g++;
73 }
74 }
75 }
76 }
77
78 if (i == 6) /* { dg-warning "this condition has identical branches" } */
79 g = i * 6;
80 else
81 g = i * 6;
82
83 /* Don't warn. */
84 if (i == 7)
85 g = i / 6;
86 else
87 g = 6 / i;
88
89 if (i == 8) /* { dg-warning "this condition has identical branches" } */
90 return i * 8 * i * 8;
91 else
92 return i * 8 * i * 8;
93
94
95 if (i == 9) /* { dg-warning "this condition has identical branches" } */
96 {
97 p++;
98 return *p;
99 }
100 else
101 {
102 p++;
103 return *p;
104 }
105
106 /* Don't warn. */
107 if (i == 10)
108 return *++p;
109 else
110 return ++*p;
111
112 if (i == 11) /* { dg-warning "this condition has identical branches" } */
113 {
114 foo (6);
115 }
116 else
117 {
118 foo (6);
119 }
120
121 if (i == 12) /* { dg-warning "this condition has identical branches" } */
122 {
123 foo (6 + i), foo (2);
124 }
125 else
126 {
127 foo (6 + i), foo (2);
128 }
129
130 if (i == 13) /* { dg-warning "this condition has identical branches" } */
131 p += (g + 1);
132 else
133 p += (g + 1);
134
135 if (i == 14) /* { dg-warning "this condition has identical branches" } */
136 {
137 foo (7);
138 *p = 0;
139 foo (9);
140 }
141 else
142 {
143 foo (7);
144 *p = 0;
145 foo (9);
146 }
147
148 if (i == 15) /* { dg-warning "this condition has identical branches" } */
149 p += (g + (1 + 2));
150 else
151 p += (g + (1 + 1 + 1));
152
153 if (i == 16) /* { dg-warning "this condition has identical branches" } */
154 foo (10 + g);
155 else
156 foo (g + 10);
157
158 if (i == 17) /* { dg-warning "this condition has identical branches" } */
159 ({ foo (i); });
160 else
161 ({ foo (i); });
162
163 if (i == 18)
164 {
165 if (i == 19)
166 {
167 if (i == 20) /* { dg-warning "this condition has identical branches" } */
168 foo (++i);
169 else
170 foo (++i);
171 }
172 }
173
174 /* Don't warn. */
175 if (i == 21)
176 {
177 foo (1);
178 foo (2);
179 }
180 else
181 {
182 foo (2);
183 foo (1);
184 }
185
186 return 0;
187 }