31class BuiltinFunctionChecker :
public Checker<eval::Call> {
39 {CDM::SimpleFunc, {
"std",
"addressof"}},
40 {CDM::SimpleFunc, {
"std",
"__addressof"}},
41 {CDM::SimpleFunc, {
"std",
"as_const"}},
42 {CDM::SimpleFunc, {
"std",
"forward"}},
43 {CDM::SimpleFunc, {
"std",
"forward_like"}},
44 {CDM::SimpleFunc, {
"std",
"move"}},
45 {CDM::SimpleFunc, {
"std",
"move_if_noexcept"}},
53bool BuiltinFunctionChecker::isBuiltinLikeFunction(
55 const auto *FD = llvm::dyn_cast_or_null<FunctionDecl>(
Call.getDecl());
56 if (!FD || FD->getNumParams() != 1)
59 if (
QualType RetTy = FD->getReturnType();
63 if (
QualType ParmTy = FD->getParamDecl(0)->getType();
67 return BuiltinLikeStdFunctions.contains(
Call);
73 const auto *FD = dyn_cast_or_null<FunctionDecl>(
Call.getDecl());
78 const Expr *CE =
Call.getOriginExpr();
80 if (isBuiltinLikeFunction(
Call)) {
81 C.addTransition(state->BindExpr(CE, LCtx,
Call.getArgSVal(0)));
85 switch (FD->getBuiltinID()) {
89 case Builtin::BI__builtin_assume:
90 case Builtin::BI__assume: {
91 assert (
Call.getNumArgs() > 0);
100 C.generateSink(
C.getState(),
C.getPredecessor());
104 C.addTransition(state);
108 case Builtin::BI__builtin_unpredictable:
109 case Builtin::BI__builtin_expect:
110 case Builtin::BI__builtin_expect_with_probability:
111 case Builtin::BI__builtin_assume_aligned:
112 case Builtin::BI__builtin_addressof:
113 case Builtin::BI__builtin_function_start: {
119 assert (
Call.getNumArgs() > 0);
121 C.addTransition(state->BindExpr(CE, LCtx, Arg));
125 case Builtin::BI__builtin_dynamic_object_size:
126 case Builtin::BI__builtin_object_size:
127 case Builtin::BI__builtin_constant_p: {
135 llvm::APSInt Result = EVResult.
Val.
getInt();
141 if (FD->getBuiltinID() == Builtin::BI__builtin_constant_p) {
149 C.addTransition(state->BindExpr(CE, LCtx,
V));
159bool ento::shouldRegisterBuiltinFunctionChecker(
const CheckerManager &mgr) {
Defines enum values for all the target-independent builtin functions.
This represents one expression.
bool EvaluateAsInt(EvalResult &Result, const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects, bool InConstantContext=false) const
EvaluateAsInt - Return true if this is a constant which we can fold and convert to an integer,...
@ SE_NoSideEffects
Strictly evaluate the expression.
It wraps the AnalysisDeclContext to represent both the call stack with the help of StackFrameContext ...
A (possibly-)qualified type.
bool isPointerType() const
void apply(llvm::APSInt &Value) const
Convert a given APSInt, in place, to match this type.
APSIntType getAPSIntType(QualType T) const
Returns the type of the APSInt used to store values of the given QualType.
An immutable set of CallDescriptions.
Represents an abstract call to a function or method along a particular path.
CHECKER * registerChecker(AT &&... Args)
Used to register checkers.
BasicValueFactory & getBasicValueFactory()
nonloc::ConcreteInt makeIntVal(const IntegerLiteral *integer)
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
The JSON file list parser is used to communicate input to InstallAPI.
EvalResult is a struct with detailed info about an evaluated expression.
APValue Val
Val - This is the value the expression can be folded to.