| 1 | // RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -verify %s |
| 2 | // rdar://18716393 |
| 3 | |
| 4 | extern int a[] __attribute__((weak)); |
| 5 | int b[] = {8,13,21}; |
| 6 | struct { |
| 7 | int x[10]; |
| 8 | } c; |
| 9 | const char str[] = "text"; |
| 10 | |
| 11 | void ignore() { |
| 12 | if (!a) {} |
| 13 | } |
| 14 | void test() { |
| 15 | if (!b) {} // expected-warning {{address of array 'b' will always evaluate to 'true'}} |
| 16 | if (b == 0) {} // expected-warning {{comparison of array 'b' equal to a null pointer is always false}} |
| 17 | if (!c.x) {} // expected-warning {{address of array 'c.x' will always evaluate to 'true'}} |
| 18 | if (c.x == 0) {} // expected-warning {{comparison of array 'c.x' equal to a null pointer is always false}} |
| 19 | if (!str) {} // expected-warning {{address of array 'str' will always evaluate to 'true'}} |
| 20 | if (0 == str) {} // expected-warning {{comparison of array 'str' equal to a null pointer is always false}} |
| 21 | } |
| 22 | |
| 23 | int array[2]; |
| 24 | int test1() |
| 25 | { |
| 26 | if (!array) { // expected-warning {{address of array 'array' will always evaluate to 'true'}} |
| 27 | return array[0]; |
| 28 | } else if (array != 0) { // expected-warning {{comparison of array 'array' not equal to a null pointer is always true}} |
| 29 | return array[1]; |
| 30 | } |
| 31 | if (array == 0) // expected-warning {{comparison of array 'array' equal to a null pointer is always false}} |
| 32 | return 1; |
| 33 | return 0; |
| 34 | } |
| 35 | |
| 36 | #define NULL (void*)0 |
| 37 | |
| 38 | int test2(int* pointer, char ch, void * pv) { |
| 39 | if (!&pointer) { // expected-warning {{address of 'pointer' will always evaluate to 'true'}} |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | if (&pointer) { // expected-warning {{address of 'pointer' will always evaluate to 'true'}} |
| 44 | return 0; |
| 45 | } |
| 46 | |
| 47 | if (&pointer == NULL) {} // expected-warning {{comparison of address of 'pointer' equal to a null pointer is always false}} |
| 48 | |
| 49 | if (&pointer != NULL) {} // expected-warning {{comparison of address of 'pointer' not equal to a null pointer is always true}} |
| 50 | |
| 51 | return 1; |
| 52 | } |
| 53 | |
| 54 | void test3() { |
| 55 | if (array) { } // expected-warning {{address of array 'array' will always evaluate to 'true'}} |
| 56 | if (array != 0) {} // expected-warning {{comparison of array 'array' not equal to a null pointer is always true}} |
| 57 | if (!array) { } // expected-warning {{address of array 'array' will always evaluate to 'true'}} |
| 58 | if (array == 0) {} // expected-warning {{comparison of array 'array' equal to a null pointer is always false}} |
| 59 | |
| 60 | if (array[0] && |
| 61 | array) {} // expected-warning {{address of array 'array' will always evaluate to 'true'}} |
| 62 | |
| 63 | if (array[0] || |
| 64 | array) {} // expected-warning {{address of array 'array' will always evaluate to 'true'}} |
| 65 | |
| 66 | if (array[0] && |
| 67 | !array) {} // expected-warning {{address of array 'array' will always evaluate to 'true'}} |
| 68 | if (array[0] || |
| 69 | !array) {} // expected-warning {{address of array 'array' will always evaluate to 'true'}} |
| 70 | |
| 71 | if (array && // expected-warning {{address of array 'array' will always evaluate to 'true'}} |
| 72 | array[0]) {} |
| 73 | if (!array || // expected-warning {{address of array 'array' will always evaluate to 'true'}} |
| 74 | array[0]) {} |
| 75 | |
| 76 | if (array || // expected-warning {{address of array 'array' will always evaluate to 'true'}} |
| 77 | (!array && array[0])) {} // expected-warning {{address of array 'array' will always evaluate to 'true'}} |
| 78 | } |
| 79 | |
| 80 | // rdar://19256338 |
| 81 | #define SAVE_READ(PTR) if( (PTR) && (&result) ) *result=*PTR; |
| 82 | void _HTTPClientErrorHandler(int me) |
| 83 | { |
| 84 | int *result; |
| 85 | SAVE_READ(&me); |
| 86 | } |
| 87 | |
| 88 | void test_conditional_operator() { |
| 89 | int x; |
| 90 | x = b ? 1 : 0; // expected-warning {{address of array}} |
| 91 | x = c.x ? 1 : 0; // expected-warning {{address of array}} |
| 92 | x = str ? 1 : 0; // expected-warning {{address of array}} |
| 93 | x = array ? 1 : 0; // expected-warning {{address of array}} |
| 94 | x = &x ? 1 : 0; // expected-warning {{address of 'x'}} |
| 95 | } |
| 96 | |