1 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -disable-free -analyzer-eagerly-assume -analyzer-checker=core -analyzer-checker=deadcode -verify %s
3 int size_rdar9373039 = 1;
4 int foo_rdar9373039(const char *);
10 for (int i = 0 ; i < size_rdar9373039 ; ++i)
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}}
15 for (int i = 0 ; i < size_rdar9373039 ; ++i)
16 j += x; // expected-warning {{garbage}}
23 // This should look through the __extension__ no-op.
24 if (__extension__ (t)) return 0;
25 return *t; // expected-warning {{null pointer}}
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}}
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
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
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
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.
64 return *t; // no-warning
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;
72 actual_base = (unsigned)valB;
75 rdar10308201_aux(actual_base);
80 typedef struct Struct103 {
83 typedef unsigned int size_t;
84 void __my_memset_chk(char*, int, size_t);
85 static int radar10367606(int t) {
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)));
91 /* Caching out on a sink node. */
92 extern int fooR10376675();
93 extern int* bazR10376675();
94 extern int nR10376675;
95 void barR10376675(int *x) {
98 int *pk = bazR10376675();
99 pm = pk; //expected-warning {{never read}}
106 // Test accesses to wide character strings doesn't break the analyzer.
108 struct rdar10385775 {
111 void RDar10385775(struct rdar10385775* p) {
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 };
122 for (int i = 0; i < 2; i++) {
123 for (int j = 0; j < 4; j++) {
124 sum += array[i][j]; // no-warning
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)
133 return (c < 1 || c > 10) ? 0 : !!(c & f);
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))
143 unsigned long array[6];
145 for (; i <= count - 2; i++)
149 array[count - 1] = i;
150 rdar_12075238__aux(array[2]); // no-warning