mirror of https://github.com/microsoft/clang.git
[analyzer] Add support for __builtin_constant_p.
This builtin is evaluated in compile time. But in the analyzer we don't yet automagically evaluate all calls that can be evaluated in compile time. Patch by Felix Kostenzer! Differential Revision: https://reviews.llvm.org/D42745 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@324789 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
1774e274ac
commit
6e050d9bef
|
@ -96,7 +96,8 @@ bool BuiltinFunctionChecker::evalCall(const CallExpr *CE,
|
|||
return true;
|
||||
}
|
||||
|
||||
case Builtin::BI__builtin_object_size: {
|
||||
case Builtin::BI__builtin_object_size:
|
||||
case Builtin::BI__builtin_constant_p: {
|
||||
// This must be resolvable at compile time, so we defer to the constant
|
||||
// evaluator for a value.
|
||||
SVal V = UnknownVal();
|
||||
|
|
|
@ -64,3 +64,20 @@ void g(int i) {
|
|||
// We give up the analysis on this path.
|
||||
}
|
||||
}
|
||||
|
||||
void test_constant_p() {
|
||||
int i = 1;
|
||||
const int j = 2;
|
||||
constexpr int k = 3;
|
||||
clang_analyzer_eval(__builtin_constant_p(42) == 1); // expected-warning {{TRUE}}
|
||||
clang_analyzer_eval(__builtin_constant_p(i) == 0); // expected-warning {{TRUE}}
|
||||
clang_analyzer_eval(__builtin_constant_p(j) == 1); // expected-warning {{TRUE}}
|
||||
clang_analyzer_eval(__builtin_constant_p(k) == 1); // expected-warning {{TRUE}}
|
||||
clang_analyzer_eval(__builtin_constant_p(i + 42) == 0); // expected-warning {{TRUE}}
|
||||
clang_analyzer_eval(__builtin_constant_p(j + 42) == 1); // expected-warning {{TRUE}}
|
||||
clang_analyzer_eval(__builtin_constant_p(k + 42) == 1); // expected-warning {{TRUE}}
|
||||
clang_analyzer_eval(__builtin_constant_p(" ") == 1); // expected-warning {{TRUE}}
|
||||
clang_analyzer_eval(__builtin_constant_p(test_constant_p) == 0); // expected-warning {{TRUE}}
|
||||
clang_analyzer_eval(__builtin_constant_p(k - 3) == 0); // expected-warning {{FALSE}}
|
||||
clang_analyzer_eval(__builtin_constant_p(k - 3) == 1); // expected-warning {{TRUE}}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue