brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.8 KiB · 66efab0 Raw
99 lines · c
1// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -verify  %s2 3extern int a[] __attribute__((weak));4int b[] = {8,13,21};5struct {6  int x[10];7} c;8const char str[] = "text";9 10void ignore(void) {11  if (!a) {}12}13void 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}}20}21 22int array[2];23int test1(void)24{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];29  }30  if (array == 0) // expected-warning {{comparison of array 'array' equal to a null pointer is always false}}31    return 1;32  return 0;33}34 35#define NULL (void*)036 37int test2(int* pointer, char ch, void * pv) {38   if (!&pointer) {  // expected-warning {{address of 'pointer' will always evaluate to 'true'}}39     return 0;40   }41 42   if (&pointer) {  // expected-warning {{address of 'pointer' will always evaluate to 'true'}}43     return 0;44   }45 46   if (&pointer == NULL) {} // expected-warning {{comparison of address of 'pointer' equal to a null pointer is always false}}47 48   if (&pointer != NULL) {} // expected-warning {{comparison of address of 'pointer' not equal to a null pointer is always true}}49 50   return 1;51}52 53void 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}}58 59   if (array[0] &&60       array) {} // expected-warning {{address of array 'array' will always evaluate to 'true'}}61 62   if (array[0] ||63       array) {} // expected-warning {{address of array 'array' will always evaluate to 'true'}}64 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'}}69 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]) {}74 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'}}77 }78 79#define SAVE_READ(PTR) if( (PTR) && (&result) ) *result=*PTR;80void _HTTPClientErrorHandler(int me)81{82  int *result;83  SAVE_READ(&me);84}85 86void 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'}}93}94 95void 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}}98}99