xref: /aosp_15_r20/external/clang/test/Sema/warn-bitwise-compare.c (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -verify -Wtautological-compare %s
2*67e74705SXin Li 
3*67e74705SXin Li #define mydefine 2
4*67e74705SXin Li 
f(int x)5*67e74705SXin Li void f(int x) {
6*67e74705SXin Li   if ((8 & x) == 3) {}  // expected-warning {{bitwise comparison always evaluates to false}}
7*67e74705SXin Li   if ((x & 8) == 4) {}  // expected-warning {{bitwise comparison always evaluates to false}}
8*67e74705SXin Li   if ((x & 8) != 4) {}  // expected-warning {{bitwise comparison always evaluates to true}}
9*67e74705SXin Li   if ((2 & x) != 4) {}  // expected-warning {{bitwise comparison always evaluates to true}}
10*67e74705SXin Li   if ((x | 4) == 3) {}  // expected-warning {{bitwise comparison always evaluates to false}}
11*67e74705SXin Li   if ((x | 3) != 4) {}  // expected-warning {{bitwise comparison always evaluates to true}}
12*67e74705SXin Li   if ((5 | x) != 3) {}  // expected-warning {{bitwise comparison always evaluates to true}}
13*67e74705SXin Li   if ((x & 0x15) == 0x13) {} // expected-warning {{bitwise comparison always evaluates to false}}
14*67e74705SXin Li   if ((0x23 | x) == 0x155){} // expected-warning {{bitwise comparison always evaluates to false}}
15*67e74705SXin Li 
16*67e74705SXin Li   if ((x & 8) == 8) {}
17*67e74705SXin Li   if ((x & 8) != 8) {}
18*67e74705SXin Li   if ((x | 4) == 4) {}
19*67e74705SXin Li   if ((x | 4) != 4) {}
20*67e74705SXin Li 
21*67e74705SXin Li   if ((x & 9) == 8) {}
22*67e74705SXin Li   if ((x & 9) != 8) {}
23*67e74705SXin Li   if ((x | 4) == 5) {}
24*67e74705SXin Li   if ((x | 4) != 5) {}
25*67e74705SXin Li 
26*67e74705SXin Li   if ((x & mydefine) == 8) {}
27*67e74705SXin Li   if ((x | mydefine) == 4) {}
28*67e74705SXin Li }
29