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