1 // RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 -verify %s \
2 // RUN: -analyzer-checker=debug.ExprInspection \
3 // RUN: -analyzer-checker=unix.cstring \
4 // RUN: -analyzer-checker=unix.Malloc \
5 // RUN: -analyzer-config display-checker-name=false
7 typedef unsigned long size_t;
20 void clang_analyzer_explain(int);
21 void clang_analyzer_explain(void *);
22 void clang_analyzer_explain(const int *);
23 void clang_analyzer_explain(S
);
25 size_t clang_analyzer_getExtent(void *);
27 size_t strlen(const char *);
36 // Test strings are regex'ed because we need to match exact string
37 // rather than a substring.
39 void test_1(int param
, void *ptr
) {
40 clang_analyzer_explain(&glob
); // expected-warning-re{{{{^pointer to global variable 'glob'$}}}}
41 clang_analyzer_explain(param
); // expected-warning-re{{{{^argument 'param'$}}}}
42 clang_analyzer_explain(ptr
); // expected-warning-re{{{{^argument 'ptr'$}}}}
44 clang_analyzer_explain(param
); // expected-warning-re{{{{^signed 32-bit integer '42'$}}}}
47 void test_2(char *ptr
, int ext
) {
48 clang_analyzer_explain((void *) "asdf"); // expected-warning-re{{{{^pointer to element of type 'char' with index 0 of string literal "asdf"$}}}}
49 clang_analyzer_explain(strlen(ptr
)); // expected-warning-re{{{{^metadata of type 'unsigned long' tied to pointee of argument 'ptr'$}}}}
50 clang_analyzer_explain(conjure()); // expected-warning-re{{{{^symbol of type 'int' conjured at statement 'conjure\(\)'$}}}}
51 clang_analyzer_explain(glob
); // expected-warning-re{{{{^value derived from \(symbol of type 'int' conjured at statement 'conjure\(\)'\) for global variable 'glob'$}}}}
52 clang_analyzer_explain(glob_ptr
); // expected-warning-re{{{{^value derived from \(symbol of type 'int' conjured at statement 'conjure\(\)'\) for global variable 'glob_ptr'$}}}}
53 clang_analyzer_explain(clang_analyzer_getExtent(ptr
)); // expected-warning-re{{{{^extent of pointee of argument 'ptr'$}}}}
54 int *x
= new int[ext
];
55 clang_analyzer_explain(x
); // expected-warning-re{{{{^pointer to element of type 'int' with index 0 of heap segment that starts at symbol of type 'int \*' conjured at statement 'new int \[ext\]'$}}}}
56 // Sic! What gets computed is the extent of the element-region.
57 clang_analyzer_explain(clang_analyzer_getExtent(x
)); // expected-warning-re{{{{^\(argument 'ext'\) \* 4$}}}}
62 clang_analyzer_explain(&s
); // expected-warning-re{{{{^pointer to parameter 's'$}}}}
63 clang_analyzer_explain(s
.z
); // expected-warning-re{{{{^initial value of field 'z' of parameter 's'$}}}}
64 clang_analyzer_explain(&s
.s2
[5].y
[3]); // expected-warning-re{{{{^pointer to element of type 'int' with index 3 of field 'y' of base object 'S::S3' inside element of type 'struct S::S2' with index 5 of field 's2' of parameter 's'$}}}}
66 clang_analyzer_explain(s
.s2
[7].x
); // expected-warning-re{{{{^concrete memory address '0'$}}}}
67 // FIXME: we need to be explaining '1' rather than '0' here; not explainer bug.
68 clang_analyzer_explain(s
.s2
[7].x
+ 1); // expected-warning-re{{{{^concrete memory address '0'$}}}}
72 void test_4(int x
, int y
) {
75 clang_analyzer_explain(-x
); // expected-warning-re{{{{^\- \(argument 'x'\)$}}}}
76 clang_analyzer_explain(x
+ 1); // expected-warning-re{{{{^\(argument 'x'\) \+ 1$}}}}
77 clang_analyzer_explain(1 + y
); // expected-warning-re{{{{^\(argument 'y'\) \+ 1$}}}}
78 clang_analyzer_explain(x
+ y
); // expected-warning-re{{{{^\(argument 'x'\) \+ \(argument 'y'\)$}}}}
79 clang_analyzer_explain(z
); // expected-warning-re{{{{^undefined value$}}}}
80 clang_analyzer_explain(&z
); // expected-warning-re{{{{^pointer to local variable 'z'$}}}}
81 clang_analyzer_explain(stat
); // expected-warning-re{{{{^signed 32-bit integer '0'$}}}}
82 clang_analyzer_explain(&stat
); // expected-warning-re{{{{^pointer to static local variable 'stat'$}}}}
83 clang_analyzer_explain(stat_glob
); // expected-warning-re{{{{^initial value of global variable 'stat_glob'$}}}}
84 clang_analyzer_explain(&stat_glob
); // expected-warning-re{{{{^pointer to global variable 'stat_glob'$}}}}
85 clang_analyzer_explain((int[]){1, 2, 3}); // expected-warning-re{{{{^pointer to element of type 'int' with index 0 of temporary object constructed at statement '\(int\[3\]\)\{1, 2, 3\}'$}}}}
94 clang_analyzer_explain(this); // expected-warning-re{{{{^pointer to 'this' object$}}}}
95 clang_analyzer_explain(&x
[i
]); // expected-warning-re{{{{^pointer to element of type 'int' with index 'argument 'i'' of field 'x' of 'this' object$}}}}
96 clang_analyzer_explain(__builtin_alloca(i
)); // expected-warning-re{{{{^pointer to region allocated by '__builtin_alloca\(i\)'$}}}}
99 } // end of anonymous namespace
102 clang_analyzer_explain(conjure_S()); // expected-warning-re{{{{^lazily frozen compound value of 1st parameter of function 'clang_analyzer_explain\(\)'$}}}}
103 clang_analyzer_explain(conjure_S().z
); // expected-warning-re{{{{^value derived from \(symbol of type 'int' conjured at statement 'conjure_S\(\)'\) for field 'z' of temporary object constructed at statement 'conjure_S\(\)'$}}}}
108 C_top_level(int param
) {
109 clang_analyzer_explain(¶m
); // expected-warning-re{{{{^pointer to parameter 'param'$}}}}
113 class C_non_top_level
{
115 C_non_top_level(int param
) {
116 clang_analyzer_explain(¶m
); // expected-warning-re{{{{^pointer to parameter 'param'$}}}}
121 C_non_top_level
c(n
);
123 auto lambda_top_level
= [n
](int param
) {
124 clang_analyzer_explain(¶m
); // expected-warning-re{{{{^pointer to parameter 'param'$}}}}
126 auto lambda_non_top_level
= [n
](int param
) {
127 clang_analyzer_explain(¶m
); // expected-warning-re{{{{^pointer to parameter 'param'$}}}}
130 lambda_non_top_level(n
);