PR c++/67273
[official-gcc.git] / gcc / testsuite / c-c++-common / Wduplicated-branches-1.c
blobc0b93fcf97a0c7732dedb42dd96c569600570dfc
1 /* PR c/64279 */
2 /* { dg-do compile } */
3 /* { dg-options "-Wduplicated-branches -O2" } */
5 extern void foo (int);
6 extern int g;
7 extern int a[10];
9 int
10 f (int i, int *p)
12 const int j = 0;
13 if (j == 0)
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;
22 if (i)
24 else
27 if (i == 0) /* { dg-warning "this condition has identical branches" } */
28 return 0;
29 else
30 return 0;
32 if (i == 1) /* { dg-warning "this condition has identical branches" } */
34 g = 10;
36 else
38 g = 10;
41 const char *s;
42 if (i == 2) /* { dg-warning "this condition has identical branches" } */
43 s = "foo";
44 else
45 s = "foo";
47 if (i == 3) /* { dg-warning "this condition has identical branches" } */
48 g = a[i];
49 else
50 g = a[i];
52 if (i == 4) /* { dg-warning "this condition has identical branches" } */
53 return i ? 1 : g;
54 else
55 return i ? 1 : g;
57 if (i == 5) /* { dg-warning "this condition has identical branches" } */
62 g++;
67 else
72 g++;
78 if (i == 6) /* { dg-warning "this condition has identical branches" } */
79 g = i * 6;
80 else
81 g = i * 6;
83 /* Don't warn. */
84 if (i == 7)
85 g = i / 6;
86 else
87 g = 6 / i;
89 if (i == 8) /* { dg-warning "this condition has identical branches" } */
90 return i * 8 * i * 8;
91 else
92 return 8 * i * 8 * i;
95 if (i == 9) /* { dg-warning "this condition has identical branches" } */
97 p++;
98 return *p;
100 else
102 p++;
103 return *p;
106 /* Don't warn. */
107 if (i == 10)
108 return *++p;
109 else
110 return ++*p;
112 if (i == 11) /* { dg-warning "this condition has identical branches" } */
114 foo (6);
116 else
118 foo (6);
121 if (i == 12) /* { dg-warning "this condition has identical branches" } */
123 foo (6 + i), foo (2);
125 else
127 foo (6 + i), foo (2);
130 if (i == 13) /* { dg-warning "this condition has identical branches" } */
131 p += (g + 1);
132 else
133 p += (g + 1);
135 if (i == 14) /* { dg-warning "this condition has identical branches" } */
137 foo (7);
138 *p = 0;
139 foo (9);
141 else
143 foo (7);
144 *p = 0;
145 foo (9);
148 if (i == 15) /* { dg-warning "this condition has identical branches" } */
149 p += (g + (1 + 2));
150 else
151 p += (g + (1 + 1 + 1));
153 if (i == 16) /* { dg-warning "this condition has identical branches" } */
154 foo (10 + g);
155 else
156 foo (g + 10);
158 if (i == 17) /* { dg-warning "this condition has identical branches" } */
159 ({ foo (i); });
160 else
161 ({ foo (i); });
163 if (i == 18)
165 if (i == 19)
167 if (i == 20) /* { dg-warning "this condition has identical branches" } */
168 foo (++i);
169 else
170 foo (++i);
174 /* Don't warn. */
175 if (i == 21)
177 foo (1);
178 foo (2);
180 else
182 foo (2);
183 foo (1);
186 return 0;