PR tree-optimization/86401
[official-gcc.git] / gcc / testsuite / c-c++-common / Wduplicated-cond-1.c
blob179c4194da7de7abeebdb21e6b7482fd1dd65b5e
1 /* PR c/64249 */
2 /* { dg-do compile } */
3 /* { dg-options "-Wduplicated-cond" } */
5 #ifndef __cplusplus
6 # define bool _Bool
7 # define true 1
8 # define false 0
9 #endif
11 extern int foo (void);
13 int
14 fn1 (int n)
16 if (n == 1) /* { dg-message "previously used here" } */
17 return -1;
18 else if (n == 2)
19 return 0;
20 else if (n == 1) /* { dg-warning "duplicated .if. condition" } */
21 return 1;
22 return 0;
25 int
26 fn2 (void)
28 if (4)
29 return 1;
30 else if (4)
31 return 2;
33 #define N 10
34 if (N)
35 return 3;
36 else if (N)
37 return 4;
40 int
41 fn3 (int n)
43 if (n == 42)
44 return 1;
45 if (n == 42)
46 return 2;
48 if (n)
49 if (n)
50 if (n)
51 if (n)
52 return 42;
54 if (!n)
55 return 10;
56 else
57 return 11;
60 int
61 fn4 (int n)
63 if (n > 0)
65 if (n == 1) /* { dg-message "previously used here" } */
66 return 1;
67 else if (n == 1) /* { dg-warning "duplicated .if. condition" } */
68 return 2;
70 else if (n < 0)
72 if (n < -1)
73 return 6;
74 else if (n < -2)
76 if (n == -10) /* { dg-message "previously used here" } */
77 return 3;
78 else if (n == -10) /* { dg-warning "duplicated .if. condition" } */
79 return 4;
82 else
83 return 7;
84 return 0;
87 struct S { long p, q; };
89 int
90 fn5 (struct S *s)
92 if (!s->p) /* { dg-message "previously used here" } */
93 return 12345;
94 else if (!s->p) /* { dg-warning "duplicated .if. condition" } */
95 return 1234;
96 return 0;
99 int
100 fn6 (int n)
102 if (n) /* { dg-message "previously used here" } */
103 return n;
104 else if (n) /* { dg-warning "duplicated .if. condition" } */
105 return n;
106 else if (n) /* { dg-warning "duplicated .if. condition" } */
107 return n;
108 else if (n) /* { dg-warning "duplicated .if. condition" } */
109 return n;
110 else if (n) /* { dg-warning "duplicated .if. condition" } */
111 return n;
112 else if (n) /* { dg-warning "duplicated .if. condition" } */
113 return n;
114 else if (n) /* { dg-warning "duplicated .if. condition" } */
115 return n;
116 else if (n) /* { dg-warning "duplicated .if. condition" } */
117 return n;
118 return 0;
122 fn7 (int n)
124 if (n == 0) /* { dg-message "previously used here" } */
125 return 10;
126 else if (n == 1) /* { dg-message "previously used here" } */
127 return 11;
128 else if (n == 2) /* { dg-message "previously used here" } */
129 return 12;
130 else if (n == 3) /* { dg-message "previously used here" } */
131 return 13;
132 else if (n == 4) /* { dg-message "previously used here" } */
133 return 14;
134 else if (n == 5) /* { dg-message "previously used here" } */
135 return 15;
136 else if (n == 6) /* { dg-message "previously used here" } */
137 return 16;
138 else if (n == 7) /* { dg-message "previously used here" } */
139 return 17;
140 else if (n == 0) /* { dg-warning "duplicated .if. condition" } */
141 return 100;
142 else if (n == 1) /* { dg-warning "duplicated .if. condition" } */
143 return 101;
144 else if (n == 2) /* { dg-warning "duplicated .if. condition" } */
145 return 102;
146 else if (n == 3) /* { dg-warning "duplicated .if. condition" } */
147 return 103;
148 else if (n == 4) /* { dg-warning "duplicated .if. condition" } */
149 return 104;
150 else if (n == 5) /* { dg-warning "duplicated .if. condition" } */
151 return 105;
152 else if (n == 6) /* { dg-warning "duplicated .if. condition" } */
153 return 106;
154 else if (n == 7) /* { dg-warning "duplicated .if. condition" } */
155 return 107;
156 return 0;
160 fn8 (bool b)
162 if (!b) /* { dg-message "previously used here" } */
163 return 16;
164 else if (!b) /* { dg-warning "duplicated .if. condition" } */
165 return 27;
166 else
167 return 64;
171 fn9 (int i, int j, int k)
173 if (i > 0 && j > 0 && k > 0) /* { dg-message "previously used here" } */
174 return -999;
175 else
176 if (i > 0 && j > 0 && k > 0) /* { dg-warning "duplicated .if. condition" } */
177 return 999;
178 else
179 return 0;
183 fn10 (void)
185 if (foo ())
186 return 17329;
187 else if (foo ())
188 return 18409;
189 return 0;
193 fn11 (int n)
195 if (++n == 10)
196 return 666;
197 else if (++n == 10)
198 return 9;
199 return 0;