blob: bef5b0618183d3cd46ab37151e2e62cbeda6c8ba [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}