blob: de6f959b9d8c7d39998c30de077f32a9627c7dda [file] [log] [blame]
Anna Zaksbfa9ab82013-01-24 23:15:30 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-config ipa=none -fblocks -verify %s
Jordan Rose697a6852013-02-14 19:06:11 +00002// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-config ipa=none -fblocks -verify -x c++ %s
Jordan Rose740d4902012-07-02 19:27:35 +00003
4void clang_analyzer_eval(int);
5
6void testInvalidation() {
7 __block int i = 0;
8 ^{
9 ++i;
10 }();
11
12 // Under inlining, we will know that i == 1.
13 clang_analyzer_eval(i == 0); // expected-warning{{UNKNOWN}}
14}
Jordan Rose697a6852013-02-14 19:06:11 +000015
16
17const int globalConstant = 1;
18void testCapturedConstants() {
19 const int localConstant = 2;
20 static const int staticConstant = 3;
21
22 ^{
23 clang_analyzer_eval(globalConstant == 1); // expected-warning{{TRUE}}
24 clang_analyzer_eval(localConstant == 2); // expected-warning{{TRUE}}
25 clang_analyzer_eval(staticConstant == 3); // expected-warning{{TRUE}}
26 }();
27}
28
29typedef const int constInt;
30constInt anotherGlobalConstant = 1;
31void testCapturedConstantsTypedef() {
32 constInt localConstant = 2;
33 static constInt staticConstant = 3;
34
35 ^{
36 clang_analyzer_eval(anotherGlobalConstant == 1); // expected-warning{{TRUE}}
37 clang_analyzer_eval(localConstant == 2); // expected-warning{{TRUE}}
38 clang_analyzer_eval(staticConstant == 3); // expected-warning{{TRUE}}
39 }();
40}