36 #include "llvm/ADT/APSInt.h" 37 #include "llvm/ADT/None.h" 38 #include "llvm/ADT/Optional.h" 39 #include "llvm/Support/Casting.h" 40 #include "llvm/Support/Compiler.h" 44 using namespace clang;
51 void SValBuilder::anchor() {}
106 const llvm::APSInt& I = CI->getValue();
176 unsigned visitCount) {
194 unsigned VisitCount) {
241 assert(!DD || isa<CXXMethodDecl>(DD) || isa<FieldDecl>(DD));
243 if (
const auto *MD = dyn_cast_or_null<CXXMethodDecl>(DD)) {
263 unsigned blockCount) {
292 case Stmt::AddrLabelExprClass:
293 return makeLoc(cast<AddrLabelExpr>(E));
295 case Stmt::CXXScalarValueInitExprClass:
296 case Stmt::ImplicitValueInitExprClass:
299 case Stmt::ObjCStringLiteralClass: {
300 const auto *SL = cast<ObjCStringLiteral>(E);
304 case Stmt::StringLiteralClass: {
305 const auto *SL = cast<StringLiteral>(E);
311 case Stmt::CharacterLiteralClass: {
312 const auto *C = cast<CharacterLiteral>(E);
313 return makeIntVal(C->getValue(), C->getType());
316 case Stmt::CXXBoolLiteralExprClass:
319 case Stmt::TypeTraitExprClass: {
320 const auto *TE = cast<TypeTraitExpr>(E);
324 case Stmt::IntegerLiteralClass:
327 case Stmt::ObjCBoolLiteralExprClass:
330 case Stmt::CXXNullPtrLiteralExprClass:
333 case Stmt::CStyleCastExprClass:
334 case Stmt::CXXFunctionalCastExprClass:
335 case Stmt::CXXConstCastExprClass:
336 case Stmt::CXXReinterpretCastExprClass:
337 case Stmt::CXXStaticCastExprClass:
338 case Stmt::ImplicitCastExprClass: {
339 const auto *CE = cast<CastExpr>(E);
340 switch (CE->getCastKind()) {
343 case CK_ArrayToPointerDecay:
344 case CK_IntegralToPointer:
347 const Expr *SE = CE->getSubExpr();
391 if (symLHS && symRHS &&
393 return makeNonLoc(symLHS, Op, symRHS, ResultTy);
397 return makeNonLoc(symLHS, Op, rInt->getValue(), ResultTy);
401 return makeNonLoc(lInt->getValue(), Op, symRHS, ResultTy);
429 assert(op == BO_Add);
441 return state->isNonNull(
evalEQ(state, lhs, rhs));
451 return evalEQ(state, static_cast<SVal>(lhs), static_cast<SVal>(rhs))
469 if (Quals1 != Quals2)
495 return evalCast(val, castTy, originalTy);
499 return evalCast(val, castTy, originalTy);
506 makeIntVal(ToTypeMax.isUnsigned() ? ToTypeMax.getZExtValue()
507 : ToTypeMax.getSExtValue(),
517 std::tie(IsNotTruncated, IsTruncated) = state->assume(CompVal);
518 if (!IsNotTruncated && IsTruncated) {
523 return evalCast(val, castTy, originalTy);
546 return makeNonLoc(Sym, BO_NE, BVF.getValue(0, Sym->getType()), castTy);
569 if (
const MemRegion *R = LV->getLoc().getAsRegion()) {
586 if (
const auto *arrayT =
589 QualType elemTy = arrayT->getElementType();
Defines the clang::ASTContext interface.
Represents a function declaration or definition.
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.
bool isRecordType() const
BlockCodeRegion - A region that represents code texts of blocks (closures).
const Type * getTypeForDecl() const
virtual QualType getValueType() const =0
SVal makeSymExprValNN(ProgramStateRef state, BinaryOperator::Opcode op, NonLoc lhs, NonLoc rhs, QualType resultTy)
Constructs a symbolic expression for two non-location values.
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...
bool EvaluateAsInt(llvm::APSInt &Result, const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects) const
EvaluateAsInt - Return true if this is a constant which we can fold and convert to an integer...
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
SubEngine * getOwningEngine()
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.
QualType getThisType(ASTContext &C) const
Returns the type of the this pointer.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
const SymIntExpr * getSymIntExpr(const SymExpr *lhs, BinaryOperator::Opcode op, const llvm::APSInt &rhs, QualType t)
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.
Pepresents a block literal declaration, which is like an unnamed FunctionDecl.
Expr - This represents one expression.
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
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.
DefinedOrUnknownSVal conjureSymbolVal(const void *symbolTag, const Expr *expr, const LocationContext *LCtx, unsigned count)
Create a new symbol with a unique 'name'.
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.
unsigned getMaxSymbolComplexity()
Returns the maximum complexity of symbolic constraint (50 by default).
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)
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 SymbolConjured * conjureSymbol(const Stmt *E, const LocationContext *LCtx, QualType T, unsigned VisitCount, const void *SymbolTag=nullptr)
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 ...
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
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
IgnoreParens - Ignore parentheses.
virtual AnalysisManager & getAnalysisManager()=0