Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Sema / warn-tautological-compare.c
blob66efab046278a89c25a67c890a81ef1485daffc6
1 // RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -verify %s
3 extern int a[] __attribute__((weak));
4 int b[] = {8,13,21};
5 struct {
6 int x[10];
7 } c;
8 const char str[] = "text";
10 void ignore(void) {
11 if (!a) {}
13 void test(void) {
14 if (!b) {} // expected-warning {{address of array 'b' will always evaluate to 'true'}}
15 if (b == 0) {} // expected-warning {{comparison of array 'b' equal to a null pointer is always false}}
16 if (!c.x) {} // expected-warning {{address of array 'c.x' will always evaluate to 'true'}}
17 if (c.x == 0) {} // expected-warning {{comparison of array 'c.x' equal to a null pointer is always false}}
18 if (!str) {} // expected-warning {{address of array 'str' will always evaluate to 'true'}}
19 if (0 == str) {} // expected-warning {{comparison of array 'str' equal to a null pointer is always false}}
22 int array[2];
23 int test1(void)
25 if (!array) { // expected-warning {{address of array 'array' will always evaluate to 'true'}}
26 return array[0];
27 } else if (array != 0) { // expected-warning {{comparison of array 'array' not equal to a null pointer is always true}}
28 return array[1];
30 if (array == 0) // expected-warning {{comparison of array 'array' equal to a null pointer is always false}}
31 return 1;
32 return 0;
35 #define NULL (void*)0
37 int test2(int* pointer, char ch, void * pv) {
38 if (!&pointer) { // expected-warning {{address of 'pointer' will always evaluate to 'true'}}
39 return 0;
42 if (&pointer) { // expected-warning {{address of 'pointer' will always evaluate to 'true'}}
43 return 0;
46 if (&pointer == NULL) {} // expected-warning {{comparison of address of 'pointer' equal to a null pointer is always false}}
48 if (&pointer != NULL) {} // expected-warning {{comparison of address of 'pointer' not equal to a null pointer is always true}}
50 return 1;
53 void test3(void) {
54 if (array) { } // expected-warning {{address of array 'array' will always evaluate to 'true'}}
55 if (array != 0) {} // expected-warning {{comparison of array 'array' not equal to a null pointer is always true}}
56 if (!array) { } // expected-warning {{address of array 'array' will always evaluate to 'true'}}
57 if (array == 0) {} // expected-warning {{comparison of array 'array' equal to a null pointer is always false}}
59 if (array[0] &&
60 array) {} // expected-warning {{address of array 'array' will always evaluate to 'true'}}
62 if (array[0] ||
63 array) {} // expected-warning {{address of array 'array' will always evaluate to 'true'}}
65 if (array[0] &&
66 !array) {} // expected-warning {{address of array 'array' will always evaluate to 'true'}}
67 if (array[0] ||
68 !array) {} // expected-warning {{address of array 'array' will always evaluate to 'true'}}
70 if (array && // expected-warning {{address of array 'array' will always evaluate to 'true'}}
71 array[0]) {}
72 if (!array || // expected-warning {{address of array 'array' will always evaluate to 'true'}}
73 array[0]) {}
75 if (array || // expected-warning {{address of array 'array' will always evaluate to 'true'}}
76 (!array && array[0])) {} // expected-warning {{address of array 'array' will always evaluate to 'true'}}
79 #define SAVE_READ(PTR) if( (PTR) && (&result) ) *result=*PTR;
80 void _HTTPClientErrorHandler(int me)
82 int *result;
83 SAVE_READ(&me);
86 void test_conditional_operator(void) {
87 int x;
88 x = b ? 1 : 0; // expected-warning {{address of array}}
89 x = c.x ? 1 : 0; // expected-warning {{address of array}}
90 x = str ? 1 : 0; // expected-warning {{address of array}}
91 x = array ? 1 : 0; // expected-warning {{address of array}}
92 x = &x ? 1 : 0; // expected-warning {{address of 'x'}}
95 void test4(void) {
96 int *a = (void *) 0;
97 int b = (&a) == ((void *) 0); // expected-warning {{comparison of address of 'a' equal to a null pointer is always false}}