2013-01-25 07:15:30 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-config ipa=none -fblocks -verify %s
|
[analyzer] Try constant-evaluation for all variables, not just globals.
In C++, constants captured by lambdas (and blocks) are not actually stored
in the closure object, since they can be expanded at compile time. In this
case, they will have no binding when we go to look them up. Previously,
RegionStore thought they were uninitialized stack variables; now, it checks
to see if they are a constant we know how to evaluate, using the same logic
as r175026.
This particular code path is only for scalar variables. Constant arrays and
structs are still unfortunately unhandled; we'll need a stronger solution
for those.
This may have a small performance impact, but only for truly-undefined
local variables, captures in a non-inlined block, and non-constant globals.
Even then, in the non-constant case we're only doing a quick type check.
<rdar://problem/13105553>
llvm-svn: 175194
2013-02-15 03:06:11 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-config ipa=none -fblocks -verify -x c++ %s
|
2012-07-03 03:27:35 +08:00
|
|
|
|
|
|
|
void clang_analyzer_eval(int);
|
|
|
|
|
|
|
|
void testInvalidation() {
|
|
|
|
__block int i = 0;
|
|
|
|
^{
|
|
|
|
++i;
|
|
|
|
}();
|
|
|
|
|
|
|
|
// Under inlining, we will know that i == 1.
|
|
|
|
clang_analyzer_eval(i == 0); // expected-warning{{UNKNOWN}}
|
|
|
|
}
|
[analyzer] Try constant-evaluation for all variables, not just globals.
In C++, constants captured by lambdas (and blocks) are not actually stored
in the closure object, since they can be expanded at compile time. In this
case, they will have no binding when we go to look them up. Previously,
RegionStore thought they were uninitialized stack variables; now, it checks
to see if they are a constant we know how to evaluate, using the same logic
as r175026.
This particular code path is only for scalar variables. Constant arrays and
structs are still unfortunately unhandled; we'll need a stronger solution
for those.
This may have a small performance impact, but only for truly-undefined
local variables, captures in a non-inlined block, and non-constant globals.
Even then, in the non-constant case we're only doing a quick type check.
<rdar://problem/13105553>
llvm-svn: 175194
2013-02-15 03:06:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
const int globalConstant = 1;
|
|
|
|
void testCapturedConstants() {
|
|
|
|
const int localConstant = 2;
|
|
|
|
static const int staticConstant = 3;
|
|
|
|
|
|
|
|
^{
|
|
|
|
clang_analyzer_eval(globalConstant == 1); // expected-warning{{TRUE}}
|
|
|
|
clang_analyzer_eval(localConstant == 2); // expected-warning{{TRUE}}
|
|
|
|
clang_analyzer_eval(staticConstant == 3); // expected-warning{{TRUE}}
|
|
|
|
}();
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef const int constInt;
|
|
|
|
constInt anotherGlobalConstant = 1;
|
|
|
|
void testCapturedConstantsTypedef() {
|
|
|
|
constInt localConstant = 2;
|
|
|
|
static constInt staticConstant = 3;
|
|
|
|
|
|
|
|
^{
|
|
|
|
clang_analyzer_eval(anotherGlobalConstant == 1); // expected-warning{{TRUE}}
|
|
|
|
clang_analyzer_eval(localConstant == 2); // expected-warning{{TRUE}}
|
|
|
|
clang_analyzer_eval(staticConstant == 3); // expected-warning{{TRUE}}
|
|
|
|
}();
|
|
|
|
}
|