PR tree-optimization/86401
[official-gcc.git] / gcc / testsuite / c-c++-common / Wduplicated-cond-2.c
blobc424e76644289bed57b21c79d1560534809611f2
1 /* PR c/64249 */
2 /* { dg-do compile } */
3 /* { dg-options "-Wall" } */
4 /* { dg-skip-if "PR67819" { *-*-* } } */
6 #ifndef __cplusplus
7 # define bool _Bool
8 # define true 1
9 # define false 0
10 #endif
12 extern int foo (void);
14 int
15 fn1 (int n)
17 if (n == 1) /* { dg-message "previously used here" } */
18 return -1;
19 else if (n == 2)
20 return 0;
21 else if (n == 1) /* { dg-warning "duplicated .if. condition" } */
22 return 1;
23 return 0;
26 int
27 fn2 (void)
29 if (4)
30 return 1;
31 else if (4)
32 return 2;
34 #define N 10
35 if (N)
36 return 3;
37 else if (N)
38 return 4;
41 int
42 fn3 (int n)
44 if (n == 42)
45 return 1;
46 if (n == 42)
47 return 2;
49 if (n)
50 if (n)
51 if (n)
52 if (n)
53 return 42;
55 if (!n)
56 return 10;
57 else
58 return 11;
61 int
62 fn4 (int n)
64 if (n > 0)
66 if (n == 1) /* { dg-message "previously used here" } */
67 return 1;
68 else if (n == 1) /* { dg-warning "duplicated .if. condition" } */
69 return 2;
71 else if (n < 0)
73 if (n < -1)
74 return 6;
75 else if (n < -2)
77 if (n == -10) /* { dg-message "previously used here" } */
78 return 3;
79 else if (n == -10) /* { dg-warning "duplicated .if. condition" } */
80 return 4;
83 else
84 return 7;
85 return 0;
88 struct S { long p, q; };
90 int
91 fn5 (struct S *s)
93 if (!s->p) /* { dg-message "previously used here" } */
94 return 12345;
95 else if (!s->p) /* { dg-warning "duplicated .if. condition" } */
96 return 1234;
97 return 0;
101 fn6 (int n)
103 if (n) /* { dg-message "previously used here" } */
104 return n;
105 else if (n) /* { dg-warning "duplicated .if. condition" } */
106 return n;
107 else if (n) /* { dg-warning "duplicated .if. condition" } */
108 return n;
109 else if (n) /* { dg-warning "duplicated .if. condition" } */
110 return n;
111 else if (n) /* { dg-warning "duplicated .if. condition" } */
112 return n;
113 else if (n) /* { dg-warning "duplicated .if. condition" } */
114 return n;
115 else if (n) /* { dg-warning "duplicated .if. condition" } */
116 return n;
117 else if (n) /* { dg-warning "duplicated .if. condition" } */
118 return n;
119 return 0;
123 fn7 (int n)
125 if (n == 0) /* { dg-message "previously used here" } */
126 return 10;
127 else if (n == 1) /* { dg-message "previously used here" } */
128 return 11;
129 else if (n == 2) /* { dg-message "previously used here" } */
130 return 12;
131 else if (n == 3) /* { dg-message "previously used here" } */
132 return 13;
133 else if (n == 4) /* { dg-message "previously used here" } */
134 return 14;
135 else if (n == 5) /* { dg-message "previously used here" } */
136 return 15;
137 else if (n == 6) /* { dg-message "previously used here" } */
138 return 16;
139 else if (n == 7) /* { dg-message "previously used here" } */
140 return 17;
141 else if (n == 0) /* { dg-warning "duplicated .if. condition" } */
142 return 100;
143 else if (n == 1) /* { dg-warning "duplicated .if. condition" } */
144 return 101;
145 else if (n == 2) /* { dg-warning "duplicated .if. condition" } */
146 return 102;
147 else if (n == 3) /* { dg-warning "duplicated .if. condition" } */
148 return 103;
149 else if (n == 4) /* { dg-warning "duplicated .if. condition" } */
150 return 104;
151 else if (n == 5) /* { dg-warning "duplicated .if. condition" } */
152 return 105;
153 else if (n == 6) /* { dg-warning "duplicated .if. condition" } */
154 return 106;
155 else if (n == 7) /* { dg-warning "duplicated .if. condition" } */
156 return 107;
157 return 0;
161 fn8 (bool b)
163 if (!b) /* { dg-message "previously used here" } */
164 return 16;
165 else if (!b) /* { dg-warning "duplicated .if. condition" } */
166 return 27;
167 else
168 return 64;
172 fn9 (int i, int j, int k)
174 if (i > 0 && j > 0 && k > 0) /* { dg-message "previously used here" } */
175 return -999;
176 else
177 if (i > 0 && j > 0 && k > 0) /* { dg-warning "duplicated .if. condition" } */
178 return 999;
179 else
180 return 0;
184 fn10 (void)
186 if (foo ())
187 return 1732984;
188 else if (foo ())
189 return 18409;
190 return 0;
194 fn11 (int n)
196 if (++n == 10)
197 return 666;
198 else if (++n == 10)
199 return 9;
200 return 0;