misc-ps.c revision 7f9b1d963d4b7e2faff7305733e3453130b402fe
1// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -disable-free -analyzer-eagerly-assume -analyzer-checker=core -analyzer-checker=deadcode -verify %s 2 3int size_rdar9373039 = 1; 4int foo_rdar9373039(const char *); 5 6int rdar93730392() { 7 int x; 8 int j = 0; 9 10 for (int i = 0 ; i < size_rdar9373039 ; ++i) 11 x = 1; 12 13 int extra = (2 + foo_rdar9373039 ("Clang") + ((4 - ((unsigned int) (2 + foo_rdar9373039 ("Clang")) % 4)) % 4)) + (2 + foo_rdar9373039 ("1.0") + ((4 - ((unsigned int) (2 + foo_rdar9373039 ("1.0")) % 4)) % 4)); // expected-warning {{never read}} 14 15 for (int i = 0 ; i < size_rdar9373039 ; ++i) 16 j += x; // expected-warning {{garbage}} 17 18 return j; 19} 20 21 22int PR8962 (int *t) { 23 // This should look through the __extension__ no-op. 24 if (__extension__ (t)) return 0; 25 return *t; // expected-warning {{null pointer}} 26} 27 28int PR8962_b (int *t) { 29 // This should still ignore the nested casts 30 // which aren't handled by a single IgnoreParens() 31 if (((int)((int)t))) return 0; 32 return *t; // expected-warning {{null pointer}} 33} 34 35int PR8962_c (int *t) { 36 // If the last element in a StmtExpr was a ParenExpr, it's still live 37 if (({ (t ? (_Bool)0 : (_Bool)1); })) return 0; 38 return *t; // no-warning 39} 40 41int PR8962_d (int *t) { 42 // If the last element in a StmtExpr is an __extension__, it's still live 43 if (({ __extension__(t ? (_Bool)0 : (_Bool)1); })) return 0; 44 return *t; // no-warning 45} 46 47int PR8962_e (int *t) { 48 // Redundant casts can mess things up! 49 // Environment used to skip through NoOp casts, but LiveVariables didn't! 50 if (({ (t ? (int)(int)0L : (int)(int)1L); })) return 0; 51 return *t; // no-warning 52} 53 54int PR8962_f (int *t) { 55 // The StmtExpr isn't a block-level expression here, 56 // the __extension__ is. But the value should be attached to the StmtExpr 57 // anyway. Make sure the block-level check is /before/ IgnoreParens. 58 if ( __extension__({ 59 _Bool r; 60 if (t) r = 0; 61 else r = 1; 62 r; 63 }) ) return 0; 64 return *t; // no-warning 65} 66 67// This previously crashed logic in the analyzer engine when evaluating locations. 68void rdar10308201_aux(unsigned val); 69void rdar10308201 (int valA, void *valB, unsigned valC) { 70 unsigned actual_base, lines; 71 if (valC == 0) { 72 actual_base = (unsigned)valB; 73 for (;;) { 74 if (valA & (1<<0)) 75 rdar10308201_aux(actual_base); 76 } 77 } 78} 79 80typedef struct Struct103 { 81 unsigned i; 82} Struct103; 83typedef unsigned int size_t; 84void __my_memset_chk(char*, int, size_t); 85static int radar10367606(int t) { 86 Struct103 overall; 87 ((__builtin_object_size ((char *) &overall, 0) != (size_t) -1) ? __builtin___memset_chk ((char *) &overall, 0, sizeof(Struct103), __builtin_object_size ((char *) &overall, 0)) : __my_memset_chk ((char *) &overall, 0, sizeof(Struct103))); 88 return 0; 89} 90 91/* Caching out on a sink node. */ 92extern int fooR10376675(); 93extern int* bazR10376675(); 94extern int nR10376675; 95void barR10376675(int *x) { 96 int *pm; 97 if (nR10376675 * 2) { 98 int *pk = bazR10376675(); 99 pm = pk; //expected-warning {{never read}} 100 } 101 do { 102 *x = fooR10376675(); 103 } while (0); 104} 105 106// Test accesses to wide character strings doesn't break the analyzer. 107typedef int wchar_t; 108struct rdar10385775 { 109 wchar_t *name; 110}; 111void RDar10385775(struct rdar10385775* p) { 112 p->name = L"a"; 113} 114 115// Test double loop of array and array literals. Previously this 116// resulted in a false positive uninitailized value warning. 117void rdar10686586() { 118 int array1[] = { 1, 2, 3, 0 }; 119 int array2[] = { 1, 2, 3, 0 }; 120 int *array[] = { array1, array2 }; 121 int sum = 0; 122 for (int i = 0; i < 2; i++) { 123 for (int j = 0; j < 4; j++) { 124 sum += array[i][j]; // no-warning 125 } 126 } 127} 128 129