35 #include "llvm/ADT/APSInt.h" 36 #include "llvm/ADT/None.h" 37 #include "llvm/ADT/Optional.h" 38 #include "llvm/Support/Casting.h" 39 #include "llvm/Support/Compiler.h" 43 using namespace clang;
50 void SValBuilder::anchor() {}
105 const llvm::APSInt& I = CI->getValue();
175 unsigned visitCount) {
193 unsigned VisitCount) {
240 assert(!DD || isa<CXXMethodDecl>(DD) || isa<FieldDecl>(DD));
242 if (
const auto *MD = dyn_cast_or_null<CXXMethodDecl>(DD)) {
262 unsigned blockCount) {
291 case Stmt::AddrLabelExprClass:
292 return makeLoc(cast<AddrLabelExpr>(E));
294 case Stmt::CXXScalarValueInitExprClass:
295 case Stmt::ImplicitValueInitExprClass:
298 case Stmt::ObjCStringLiteralClass: {
299 const auto *SL = cast<ObjCStringLiteral>(E);
303 case Stmt::StringLiteralClass: {
304 const auto *SL = cast<StringLiteral>(E);
310 case Stmt::CharacterLiteralClass: {
311 const auto *C = cast<CharacterLiteral>(E);
312 return makeIntVal(C->getValue(), C->getType());
315 case Stmt::CXXBoolLiteralExprClass:
318 case Stmt::TypeTraitExprClass: {
319 const auto *TE = cast<TypeTraitExpr>(E);
323 case Stmt::IntegerLiteralClass:
326 case Stmt::ObjCBoolLiteralExprClass:
329 case Stmt::CXXNullPtrLiteralExprClass:
332 case Stmt::CStyleCastExprClass:
333 case Stmt::CXXFunctionalCastExprClass:
334 case Stmt::CXXConstCastExprClass:
335 case Stmt::CXXReinterpretCastExprClass:
336 case Stmt::CXXStaticCastExprClass:
337 case Stmt::ImplicitCastExprClass: {
338 const auto *CE = cast<CastExpr>(E);
339 switch (CE->getCastKind()) {
342 case CK_ArrayToPointerDecay:
343 case CK_IntegralToPointer:
346 const Expr *SE = CE->getSubExpr();
389 if (symLHS && symRHS &&
391 return makeNonLoc(symLHS, Op, symRHS, ResultTy);
395 return makeNonLoc(symLHS, Op, rInt->getValue(), ResultTy);
399 return makeNonLoc(lInt->getValue(), Op, symRHS, ResultTy);
427 assert(op == BO_Add);
439 return state->isNonNull(
evalEQ(state, lhs, rhs));
449 return evalEQ(state, static_cast<SVal>(lhs), static_cast<SVal>(rhs))
467 if (Quals1 != Quals2)
493 return evalCast(val, castTy, originalTy);
497 return evalCast(val, castTy, originalTy);
504 makeIntVal(ToTypeMax.isUnsigned() ? ToTypeMax.getZExtValue()
505 : ToTypeMax.getSExtValue(),
515 std::tie(IsNotTruncated, IsTruncated) = state->assume(CompVal);
516 if (!IsNotTruncated && IsTruncated) {
521 return evalCast(val, castTy, originalTy);
544 return makeNonLoc(Sym, BO_NE, BVF.getValue(0, Sym->getType()), castTy);
567 if (
const MemRegion *R = LV->getLoc().getAsRegion()) {
584 if (
const auto *arrayT =
587 QualType elemTy = arrayT->getElementType();
Defines the clang::ASTContext interface.
Represents a function declaration or definition.
const SymbolConjured * conjureSymbol(const Stmt *E, const LocationContext *LCtx, QualType T, unsigned VisitCount, const void *SymbolTag=nullptr)
TypedValueRegion - An abstract class representing regions having a typed value.
nonloc::ConcreteInt makeIntVal(const IntegerLiteral *integer)
DefinedSVal getBlockPointer(const BlockDecl *block, CanQualType locTy, const LocationContext *locContext, unsigned blockCount)
A (possibly-)qualified type.
MemRegion - The root abstract class for all memory regions.
bool isBlockPointerType() const
bool isMemberPointerType() const
const internal::VariadicAllOfMatcher< Stmt > stmt
Matches statements.
Stmt - This represents one statement.
const IntSymExpr * getIntSymExpr(const llvm::APSInt &lhs, BinaryOperator::Opcode op, const SymExpr *rhs, QualType t)
C Language Family Type Representation.
QualType getThisType() const
Return the type of the this pointer.
bool isRecordType() const
BlockCodeRegion - A region that represents code texts of blocks (closures).
const Type * getTypeForDecl() const
virtual QualType getValueType() const =0
ProgramStateManager & StateMgr
The base class of the type hierarchy.
virtual unsigned computeComplexity() const =0
SVal evalCast(SVal val, QualType castTy, QualType originalType)
Value representing integer constant.
MemRegionManager MemMgr
Manages the creation of memory regions.
bool isUnsignedIntegerType() const
Return true if this is an integer type that is unsigned, according to C99 6.2.5p6 [which returns true...
ASTContext & getASTContext() const
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
virtual SVal dispatchCast(SVal val, QualType castTy)=0
loc::MemRegionVal getCXXThis(const CXXMethodDecl *D, const StackFrameContext *SFC)
Return a memory region for the 'this' object reference.
NonLoc makeNonLoc(const SymExpr *lhs, BinaryOperator::Opcode op, const llvm::APSInt &rhs, QualType type)
BasicValueFactory BasicVals
Manager of APSInt values.
Defines the clang::Expr interface and subclasses for C++ expressions.
The collection of all-type qualifiers we support.
const MemRegion * castRegion(const MemRegion *region, QualType CastToTy)
castRegion - Used by ExprEngine::VisitCast to handle casts from a MemRegion* to a specific location t...
bool isVariableArrayType() const
bool UnwrapSimilarTypes(QualType &T1, QualType &T2)
Attempt to unwrap two types that may be similar (C++ [conv.qual]).
const SymbolDerived * getDerivedSymbol(SymbolRef parentSymbol, const TypedValueRegion *R)
virtual SVal evalCastFromNonLoc(NonLoc val, QualType castTy)=0
virtual SVal evalBinOpLN(ProgramStateRef state, BinaryOperator::Opcode op, Loc lhs, NonLoc rhs, QualType resultTy)=0
Create a new value which represents a binary expression with a memory location and non-location opera...
MemRegionManager & getRegionManager()
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
SVal evalIntegralCast(ProgramStateRef state, SVal val, QualType castTy, QualType originalType)
static bool canSymbolicate(QualType T)
bool isReferenceType() const
DefinedOrUnknownSVal getDerivedRegionValueSymbolVal(SymbolRef parentSymbol, const TypedValueRegion *region)
i32 captured_struct **param SharedsTy A type which contains references the shared variables *param Shareds Context with the list of shared variables from the p *TaskFunction *param Data Additional data for task generation like final * state
const SymExpr * getAsSymbolicExpression() const
getAsSymbolicExpression - If this Sval wraps a symbolic expression then return that expression...
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
const SymbolicRegion * getSymbolicRegion(SymbolRef Sym)
Retrieve or create a "symbolic" memory region.
static bool isLocType(QualType T)
BlockDataRegion - A region that represents a block instance.
APValue Val
Val - This is the value the expression can be folded to.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
SVal makeSymExprValNN(BinaryOperator::Opcode op, NonLoc lhs, NonLoc rhs, QualType resultTy)
Constructs a symbolic expression for two non-location values.
DefinedOrUnknownSVal getRegionValueSymbolVal(const TypedValueRegion *region)
Make a unique symbol for value of region.
A record of the "type" of an APSInt, used for conversions.
NonLoc makeCompoundVal(QualType type, llvm::ImmutableList< SVal > vals)
DefinedSVal getFunctionPointer(const FunctionDecl *func)
const BlockCodeRegion * getBlockCodeRegion(const BlockDecl *BD, CanQualType locTy, AnalysisDeclContext *AC)
SymbolRef getAsSymbol(bool IncludeBaseRegions=false) const
If this SVal wraps a symbol return that SymbolRef.
Represents a ValueDecl that came out of a declarator.
nonloc::ConcreteInt makeBoolVal(const ObjCBoolLiteralExpr *boolean)
ConditionTruthVal areEqual(ProgramStateRef state, SVal lhs, SVal rhs)
Loc makeLoc(SymbolRef sym)
DefinedOrUnknownSVal makeZeroVal(QualType type)
Construct an SVal representing '0' for the specified type.
Represents a block literal declaration, which is like an unnamed FunctionDecl.
This represents one expression.
const SymIntExpr * getSymIntExpr(const SymExpr *lhs, BinaryOperator::Opcode op, const llvm::APSInt &rhs, QualType t)
bool isNullPtrType() const
const QualType ArrayIndexTy
The scalar type to use for array indices.
QualType getConditionType() const
bool isAnyComplexType() const
virtual SVal evalBinOpLL(ProgramStateRef state, BinaryOperator::Opcode op, Loc lhs, Loc rhs, QualType resultTy)=0
Create a new value which represents a binary expression with two memory location operands.
SVal evalBinOp(ProgramStateRef state, BinaryOperator::Opcode op, SVal lhs, SVal rhs, QualType type)
StoreManager & getStoreManager()
void removeCVRQualifiers(unsigned mask)
Optional< T > getAs() const
Convert to the specified SVal type, returning None if this SVal is not of the desired type...
const SymbolCast * getCastSymbol(const SymExpr *Operand, QualType From, QualType To)
llvm::APSInt getMaxValue() const LLVM_READONLY
Returns the maximum value for this type.
const SymSymExpr * getSymSymExpr(const SymExpr *lhs, BinaryOperator::Opcode op, const SymExpr *rhs, QualType t)
QualType getCanonicalType() const
DefinedOrUnknownSVal conjureSymbolVal(const void *symbolTag, const Expr *expr, const LocationContext *LCtx, unsigned count)
Create a new symbol with a unique 'name'.
NullPointerConstantKind isNullPointerConstant(ASTContext &Ctx, NullPointerConstantValueDependence NPC) const
isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to a Null pointer constant...
SymbolManager SymMgr
Manages the creation of symbols.
virtual SVal evalCastFromLoc(Loc val, QualType castTy)=0
const SymbolMetadata * getMetadataSymbol(const MemRegion *R, const Stmt *S, QualType T, const LocationContext *LCtx, unsigned VisitCount, const void *SymbolTag=nullptr)
Creates a metadata symbol associated with a specific region.
const MemRegion * getAsRegion() const
Represents a static or instance method of a struct/union/class.
ASTContext & getContext()
const SymbolRegionValue * getRegionValueSymbol(const TypedValueRegion *R)
Make a unique symbol for MemRegion R according to its kind.
SVal - This represents a symbolic expression, which can be either an L-value or an R-value...
Specifies that a value-dependent expression should be considered to never be a null pointer constant...
AnalyzerOptions & options
static bool shouldBeModeledWithNoOp(ASTContext &Context, QualType ToTy, QualType FromTy)
Recursively check if the pointer types are equal modulo const, volatile, and restrict qualifiers...
DefinedOrUnknownSVal getConjuredHeapSymbolVal(const Expr *E, const LocationContext *LCtx, unsigned Count)
Conjure a symbol representing heap allocated memory region.
bool isVectorType() const
virtual SVal evalBinOpNN(ProgramStateRef state, BinaryOperator::Opcode op, NonLoc lhs, NonLoc rhs, QualType resultTy)=0
Create a new value which represents a binary expression with two non- location operands.
const unsigned ArrayIndexWidth
The width of the scalar type used for array indices.
const SymbolicRegion * getSymbolicHeapRegion(SymbolRef sym)
Return a unique symbolic region belonging to heap memory space.
Dataflow Directional Tag Classes.
SVal ArrayToPointer(Loc Array, QualType ElementTy)
EvalResult is a struct with detailed info about an evaluated expression.
bool isZeroConstant() const
StmtClass getStmtClass() const
bool isBooleanType() const
SVal evalEQ(ProgramStateRef state, SVal lhs, SVal rhs)
Represents symbolic expression that isn't a location.
SVal convertToArrayIndex(SVal val)
const FunctionCodeRegion * getFunctionCodeRegion(const NamedDecl *FD)
DefinedSVal getMetadataSymbolVal(const void *symbolTag, const MemRegion *region, const Expr *expr, QualType type, const LocationContext *LCtx, unsigned count)
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
BasicValueFactory & getBasicValueFactory()
DefinedSVal getMemberPointer(const DeclaratorDecl *DD)
bool isFunctionType() const
const SymExpr * getAsSymExpr() const
const BlockDataRegion * getBlockDataRegion(const BlockCodeRegion *bc, const LocationContext *lc, unsigned blockCount)
getBlockDataRegion - Get the memory region associated with an instance of a block.
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
SubEngine & getOwningEngine()
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
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...
Represents a C++ struct/union/class.
Optional< SVal > getConstantVal(const Expr *E)
Returns the value of E, if it can be determined in a non-path-sensitive manner.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
bool isPointerType() const
nonloc::ConcreteInt makeTruthVal(bool b, QualType type)
A boolean literal, per ([C++ lex.bool] Boolean literals).
AnalysisDeclContext * getAnalysisDeclContext() const
bool isFunctionPointerType() const
QualType getUnqualifiedArrayType(QualType T, Qualifiers &Quals)
Return this type as a completely-unqualified array type, capturing the qualifiers in Quals...
bool isUnknownOrUndef() const
llvm::ImmutableList< SVal > getEmptySValList()
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point...
virtual AnalysisManager & getAnalysisManager()=0