forked from OSchip/llvm-project
[analyzer] Add modelling of __builtin_assume
Differential Revision: https://reviews.llvm.org/D33092 llvm-svn: 302880
This commit is contained in:
parent
9543a4b681
commit
3a00b41e43
|
@ -41,6 +41,22 @@ bool BuiltinFunctionChecker::evalCall(const CallExpr *CE,
|
|||
default:
|
||||
return false;
|
||||
|
||||
case Builtin::BI__builtin_assume: {
|
||||
assert (CE->arg_begin() != CE->arg_end());
|
||||
SVal ArgSVal = state->getSVal(CE->getArg(0), LCtx);
|
||||
if (ArgSVal.isUndef())
|
||||
return true; // Return true to model purity.
|
||||
|
||||
state = state->assume(ArgSVal.castAs<DefinedOrUnknownSVal>(), true);
|
||||
// FIXME: do we want to warn here? Not right now. The most reports might
|
||||
// come from infeasible paths, thus being false positives.
|
||||
if (!state)
|
||||
return true;
|
||||
|
||||
C.addTransition(state);
|
||||
return true;
|
||||
}
|
||||
|
||||
case Builtin::BI__builtin_unpredictable:
|
||||
case Builtin::BI__builtin_expect:
|
||||
case Builtin::BI__builtin_assume_aligned:
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s
|
||||
|
||||
void clang_analyzer_eval(int);
|
||||
|
||||
void f(int i) {
|
||||
__builtin_assume(i < 10);
|
||||
clang_analyzer_eval(i < 15); // expected-warning {{TRUE}}
|
||||
}
|
Loading…
Reference in New Issue