1 /* PR c/64249 */
2 /* { dg-do compile } */
3 /* { dg-options "-Wduplicated-cond" } */
4
5 #ifndef __cplusplus
6 # define bool _Bool
7 # define true 1
8 # define false 0
9 #endif
10
11 extern int foo (void);
12
13 int
fn1(int n)14 fn1 (int n)
15 {
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;
23 }
24
25 int
fn2(void)26 fn2 (void)
27 {
28 if (4)
29 return 1;
30 else if (4)
31 return 2;
32
33 #define N 10
34 if (N)
35 return 3;
36 else if (N)
37 return 4;
38 }
39
40 int
fn3(int n)41 fn3 (int n)
42 {
43 if (n == 42)
44 return 1;
45 if (n == 42)
46 return 2;
47
48 if (n)
49 if (n)
50 if (n)
51 if (n)
52 return 42;
53
54 if (!n)
55 return 10;
56 else
57 return 11;
58 }
59
60 int
fn4(int n)61 fn4 (int n)
62 {
63 if (n > 0)
64 {
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;
69 }
70 else if (n < 0)
71 {
72 if (n < -1)
73 return 6;
74 else if (n < -2)
75 {
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;
80 }
81 }
82 else
83 return 7;
84 return 0;
85 }
86
87 struct S { long p, q; };
88
89 int
fn5(struct S * s)90 fn5 (struct S *s)
91 {
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;
97 }
98
99 int
fn6(int n)100 fn6 (int n)
101 {
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;
119 }
120
121 int
fn7(int n)122 fn7 (int n)
123 {
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;
157 }
158
159 int
fn8(bool b)160 fn8 (bool b)
161 {
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;
168 }
169
170 int
fn9(int i,int j,int k)171 fn9 (int i, int j, int k)
172 {
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;
180 }
181
182 int
fn10(void)183 fn10 (void)
184 {
185 if (foo ())
186 return 17329;
187 else if (foo ())
188 return 18409;
189 return 0;
190 }
191
192 int
fn11(int n)193 fn11 (int n)
194 {
195 if (++n == 10)
196 return 666;
197 else if (++n == 10)
198 return 9;
199 return 0;
200 }
201