1176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -verify %s 2176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines// rdar://18716393 3176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 4176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hinesextern int a[] __attribute__((weak)); 5176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hinesint b[] = {8,13,21}; 6176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hinesstruct { 7176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines int x[10]; 8176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines} c; 9176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hinesconst char str[] = "text"; 10176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 11176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hinesvoid ignore() { 12176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines if (!a) {} 13176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines} 14176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hinesvoid test() { 15176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines if (!b) {} // expected-warning {{address of array 'b' will always evaluate to 'true'}} 16176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines if (b == 0) {} // expected-warning {{comparison of array 'b' equal to a null pointer is always false}} 17176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines if (!c.x) {} // expected-warning {{address of array 'c.x' will always evaluate to 'true'}} 18176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines if (c.x == 0) {} // expected-warning {{comparison of array 'c.x' equal to a null pointer is always false}} 19176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines if (!str) {} // expected-warning {{address of array 'str' will always evaluate to 'true'}} 20176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines if (0 == str) {} // expected-warning {{comparison of array 'str' equal to a null pointer is always false}} 21176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines} 22176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 23176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hinesint array[2]; 24176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hinesint test1() 25176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines{ 26176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines if (!array) { // expected-warning {{address of array 'array' will always evaluate to 'true'}} 27176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines return array[0]; 28176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines } else if (array != 0) { // expected-warning {{comparison of array 'array' not equal to a null pointer is always true}} 29176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines return array[1]; 30176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines } 31176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines if (array == 0) // expected-warning {{comparison of array 'array' equal to a null pointer is always false}} 32176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines return 1; 33176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines return 0; 34176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines} 35176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 36176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines#define NULL (void*)0 37176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 38176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hinesint test2(int* pointer, char ch, void * pv) { 39176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines if (!&pointer) { // expected-warning {{address of 'pointer' will always evaluate to 'true'}} 40176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines return 0; 41176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines } 42176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 43176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines if (&pointer) { // expected-warning {{address of 'pointer' will always evaluate to 'true'}} 44176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines return 0; 45176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines } 46176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 47176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines if (&pointer == NULL) {} // expected-warning {{comparison of address of 'pointer' equal to a null pointer is always false}} 48176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 49176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines if (&pointer != NULL) {} // expected-warning {{comparison of address of 'pointer' not equal to a null pointer is always true}} 50176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 51176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines return 1; 52176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines} 53176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 54176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hinesvoid test3() { 55176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines if (array) { } // expected-warning {{address of array 'array' will always evaluate to 'true'}} 56176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines if (array != 0) {} // expected-warning {{comparison of array 'array' not equal to a null pointer is always true}} 57176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines if (!array) { } // expected-warning {{address of array 'array' will always evaluate to 'true'}} 58176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines if (array == 0) {} // expected-warning {{comparison of array 'array' equal to a null pointer is always false}} 59176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 60176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines if (array[0] && 61176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines array) {} // expected-warning {{address of array 'array' will always evaluate to 'true'}} 62176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 63176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines if (array[0] || 64176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines array) {} // expected-warning {{address of array 'array' will always evaluate to 'true'}} 65176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 66176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines if (array[0] && 67176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines !array) {} // expected-warning {{address of array 'array' will always evaluate to 'true'}} 68176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines if (array[0] || 69176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines !array) {} // expected-warning {{address of array 'array' will always evaluate to 'true'}} 70176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 71176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines if (array && // expected-warning {{address of array 'array' will always evaluate to 'true'}} 72176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines array[0]) {} 73176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines if (!array || // expected-warning {{address of array 'array' will always evaluate to 'true'}} 74176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines array[0]) {} 75176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 76176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines if (array || // expected-warning {{address of array 'array' will always evaluate to 'true'}} 77176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines (!array && array[0])) {} // expected-warning {{address of array 'array' will always evaluate to 'true'}} 78176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines } 79176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 800e2c34f92f00628d48968dfea096d36381f494cbStephen Hines// rdar://19256338 810e2c34f92f00628d48968dfea096d36381f494cbStephen Hines#define SAVE_READ(PTR) if( (PTR) && (&result) ) *result=*PTR; 820e2c34f92f00628d48968dfea096d36381f494cbStephen Hinesvoid _HTTPClientErrorHandler(int me) 830e2c34f92f00628d48968dfea096d36381f494cbStephen Hines{ 840e2c34f92f00628d48968dfea096d36381f494cbStephen Hines int *result; 850e2c34f92f00628d48968dfea096d36381f494cbStephen Hines SAVE_READ(&me); 860e2c34f92f00628d48968dfea096d36381f494cbStephen Hines} 87b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar 88b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainarvoid test_conditional_operator() { 89b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar int x; 90b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar x = b ? 1 : 0; // expected-warning {{address of array}} 91b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar x = c.x ? 1 : 0; // expected-warning {{address of array}} 92b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar x = str ? 1 : 0; // expected-warning {{address of array}} 93b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar x = array ? 1 : 0; // expected-warning {{address of array}} 94b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar x = &x ? 1 : 0; // expected-warning {{address of 'x'}} 95b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar} 96