1 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -disable-free -analyzer-eagerly-assume -analyzer-checker=core -analyzer-checker=deadcode -verify %s 2 3 int size_rdar9373039 = 1; 4 int foo_rdar9373039(const char *); 5 6 int 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 22 int 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 28 int 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 35 int 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 41 int 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 47 int 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 54 int 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. 68 void rdar10308201_aux(unsigned val); 69 void 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 80 typedef struct Struct103 { 81 unsigned i; 82 } Struct103; 83 typedef unsigned int size_t; 84 void __my_memset_chk(char*, int, size_t); 85 static 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. */ 92 extern int fooR10376675(); 93 extern int* bazR10376675(); 94 extern int nR10376675; 95 void 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. 107 typedef int wchar_t; 108 struct rdar10385775 { 109 wchar_t *name; 110 }; 111 void 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. 117 void 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 // This example tests CFG handling of '||' nested in a ternary expression, 130 // and seeing that the analyzer doesn't crash. 131 int isctype(char c, unsigned long f) 132 { 133 return (c < 1 || c > 10) ? 0 : !!(c & f); 134 } 135 136 // Test that symbolic array offsets are modeled conservatively. 137 // This was triggering a false "use of uninitialized value" warning. 138 void rdar_12075238__aux(unsigned long y); 139 int rdar_12075238_(unsigned long count) { 140 if ((count < 3) || (count > 6)) 141 return 0; 142 143 unsigned long array[6]; 144 unsigned long i = 0; 145 for (; i <= count - 2; i++) 146 { 147 array[i] = i; 148 } 149 array[count - 1] = i; 150 rdar_12075238__aux(array[2]); // no-warning 151 return 0; 152 } 153 154 // Test that we handle an uninitialized value within a logical expression. 155 void PR14635(int *p) { 156 int a = 0, b; 157 *p = a || b; // expected-warning {{Assigned value is garbage or undefined}} 158 } 159 160 // Test handling floating point values with unary '!'. 161 int PR14634(int x) { 162 double y = (double)x; 163 return !y; 164 } 165 166