2017-03-04 02:02:02 +08:00
|
|
|
// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify -Wno-objc-literal-conversion %s
|
[analyzer] Consolidate constant evaluation logic in SValBuilder.
Previously, this was scattered across Environment (literal expressions),
ExprEngine (default arguments), and RegionStore (global constants). The
former special-cased several kinds of simple constant expressions, while
the latter two deferred to the AST's constant evaluator.
Now, these are all unified as SValBuilder::getConstantVal(). To keep
Environment fast, the special cases for simple constant expressions have
been left in, but the main benefits are that (a) unusual constants like
ObjCStringLiterals now work as default arguments and global constant
initializers, and (b) we're not duplicating code between ExprEngine and
RegionStore.
This actually caught a bug in our test suite, which is awesome: we stop
tracking allocated memory if it's passed as an argument along with some
kind of callback, but not if the callback is 0. We were testing this in
a case where the callback parameter had a default value, but that value
was 0. After this change, the analyzer now (correctly) flags that as a
leak!
<rdar://problem/13773117>
llvm-svn: 180894
2013-05-02 07:10:44 +08:00
|
|
|
|
|
|
|
void clang_analyzer_eval(bool);
|
|
|
|
@class NSString;
|
|
|
|
|
|
|
|
void sanity() {
|
|
|
|
clang_analyzer_eval(@""); // expected-warning{{TRUE}}
|
|
|
|
clang_analyzer_eval(@"abc"); // expected-warning{{TRUE}}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace rdar13773117 {
|
|
|
|
NSString *const kConstantGlobalString = @"foo";
|
|
|
|
NSString *globalString = @"bar";
|
|
|
|
|
|
|
|
extern void invalidateGlobals();
|
|
|
|
|
|
|
|
void testGlobals() {
|
|
|
|
clang_analyzer_eval(kConstantGlobalString); // expected-warning{{TRUE}}
|
|
|
|
clang_analyzer_eval(globalString); // expected-warning{{UNKNOWN}}
|
|
|
|
|
|
|
|
globalString = @"baz";
|
|
|
|
clang_analyzer_eval(globalString); // expected-warning{{TRUE}}
|
|
|
|
|
|
|
|
invalidateGlobals();
|
|
|
|
|
|
|
|
clang_analyzer_eval(kConstantGlobalString); // expected-warning{{TRUE}}
|
|
|
|
clang_analyzer_eval(globalString); // expected-warning{{UNKNOWN}}
|
|
|
|
}
|
|
|
|
|
|
|
|
NSString *returnString(NSString *input = @"garply") {
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
|
|
|
|
void testDefaultArg() {
|
|
|
|
clang_analyzer_eval(returnString(@"")); // expected-warning{{TRUE}}
|
|
|
|
clang_analyzer_eval(returnString(0)); // expected-warning{{FALSE}}
|
|
|
|
clang_analyzer_eval(returnString()); // expected-warning{{TRUE}}
|
|
|
|
}
|
|
|
|
}
|