Go to the documentation of this file.
14 #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SYMBOLMANAGER_H
15 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SYMBOLMANAGER_H
24 #include "llvm/ADT/DenseMap.h"
25 #include "llvm/ADT/DenseSet.h"
26 #include "llvm/ADT/FoldingSet.h"
27 #include "llvm/Support/Allocator.h"
37 class BasicValueFactory;
46 :
SymbolData(SymbolRegionValueKind, sym), R(r) {
54 profile.AddInteger((
unsigned) SymbolRegionValueKind);
55 profile.AddPointer(R);
58 void Profile(llvm::FoldingSetNodeID& profile)
override {
71 return SE->
getKind() == SymbolRegionValueKind;
82 const void *SymbolTag;
86 QualType t,
unsigned count,
const void *symbolTag)
87 :
SymbolData(SymbolConjuredKind, sym), S(
s), T(t), Count(count),
88 LCtx(lctx), SymbolTag(symbolTag) {
100 const void *
getTag()
const {
return SymbolTag; }
108 static void Profile(llvm::FoldingSetNodeID& profile,
const Stmt *S,
110 const void *SymbolTag) {
111 profile.AddInteger((
unsigned) SymbolConjuredKind);
112 profile.AddPointer(S);
113 profile.AddPointer(LCtx);
115 profile.AddInteger(Count);
116 profile.AddPointer(SymbolTag);
119 void Profile(llvm::FoldingSetNodeID& profile)
override {
120 Profile(profile, S, T, Count, LCtx, SymbolTag);
125 return SE->
getKind() == SymbolConjuredKind;
137 :
SymbolData(SymbolDerivedKind, sym), parentSymbol(parent), R(r) {
155 profile.AddInteger((
unsigned) SymbolDerivedKind);
156 profile.AddPointer(r);
157 profile.AddPointer(parent);
160 void Profile(llvm::FoldingSetNodeID& profile)
override {
161 Profile(profile, parentSymbol, R);
166 return SE->
getKind() == SymbolDerivedKind;
191 profile.AddInteger((
unsigned) SymbolExtentKind);
192 profile.AddPointer(R);
195 void Profile(llvm::FoldingSetNodeID& profile)
override {
201 return SE->
getKind() == SymbolExtentKind;
220 :
SymbolData(SymbolMetadataKind, sym), R(r), S(
s), T(t), LCtx(LCtx),
221 Count(count), Tag(tag) {
233 const void *
getTag()
const {
return Tag; }
243 unsigned Count,
const void *Tag) {
244 profile.AddInteger((
unsigned) SymbolMetadataKind);
245 profile.AddPointer(R);
246 profile.AddPointer(S);
248 profile.AddPointer(LCtx);
249 profile.AddInteger(Count);
250 profile.AddPointer(Tag);
253 void Profile(llvm::FoldingSetNodeID& profile)
override {
254 Profile(profile, R, S, T, LCtx, Count, Tag);
259 return SE->
getKind() == SymbolMetadataKind;
275 :
SymExpr(SymbolCastKind), Operand(In), FromTy(From), ToTy(To) {
284 Complexity = 1 + Operand->computeComplexity();
296 ID.AddInteger((
unsigned) SymbolCastKind);
308 return SE->
getKind() == SymbolCastKind;
337 return k >= BEGIN_BINARYSYMEXPRS && k <= END_BINARYSYMEXPRS;
342 return Value->computeComplexity();
359 template <
class LHSTYPE,
class RHSTYPE, SymExpr::Kind ClassKind>
388 static void Profile(llvm::FoldingSetNodeID &
ID, LHSTYPE lhs,
390 ID.AddInteger((
unsigned)ClassKind);
407 SymExpr::Kind::SymIntExprKind>;
411 SymExpr::Kind::IntSymExprKind>;
415 SymExpr::Kind::SymSymExprKind>;
418 using DataSetTy = llvm::FoldingSet<SymExpr>;
419 using SymbolDependTy =
420 llvm::DenseMap<SymbolRef, std::unique_ptr<SymbolRefSmallVectorTy>>;
426 SymbolDependTy SymbolDependencies;
428 unsigned SymbolCounter = 0;
429 llvm::BumpPtrAllocator& BPAlloc;
435 llvm::BumpPtrAllocator& bpalloc)
436 : SymbolDependencies(16), BPAlloc(bpalloc), BV(bv), Ctx(ctx) {}
447 const void *SymbolTag =
nullptr);
452 const void *SymbolTag =
nullptr) {
469 const void *SymbolTag =
nullptr);
512 using SymbolMapTy = llvm::DenseMap<SymbolRef, SymbolStatus>;
515 SymbolMapTy TheLiving;
524 llvm::DenseMap<const MemRegion *, unsigned> includedRegionCache;
536 : LCtx(Ctx),
Loc(
s), SymMgr(symmgr), reapedStore(nullptr, storeMgr) {}
543 bool isLive(
const VarRegion *VR,
bool includeStoreBindings =
false)
const;
607 #endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SYMBOLMANAGER_H
static bool isLocType(QualType T)
void dumpToStream(raw_ostream &os) const override
const SymbolConjured * conjureSymbol(const Stmt *E, const LocationContext *LCtx, QualType T, unsigned VisitCount, const void *SymbolTag=nullptr)
It wraps the AnalysisDeclContext to represent both the call stack with the help of StackFrameContext ...
void Profile(llvm::FoldingSetNodeID &ID) override
const void * getTag() const
const IntSymExpr * getIntSymExpr(const llvm::APSInt &lhs, BinaryOperator::Opcode op, const SymExpr *rhs, QualType t)
static void dumpToStreamImpl(raw_ostream &os, const SymExpr *Value)
RegionSetTy::const_iterator region_iterator
const SymSymExpr * getSymSymExpr(const SymExpr *lhs, BinaryOperator::Opcode op, const SymExpr *rhs, QualType t)
SymbolManager(ASTContext &ctx, BasicValueFactory &bv, llvm::BumpPtrAllocator &bpalloc)
A (possibly-)qualified type.
BasicValueFactory & getBasicVals()
StringRef getKindStr() const override
Get a string representation of the kind of the region.
Represents a symbolic expression involving a binary operator.
QualType getType() const override
SymbolExtent(SymbolID sym, const SubRegion *r)
static bool classof(const SymExpr *SE)
void dumpToStream(raw_ostream &os) const override
const SymbolConjured * conjureSymbol(const Expr *E, const LocationContext *LCtx, unsigned VisitCount, const void *SymbolTag=nullptr)
It represents a stack frame of the call stack (based on CallEvent).
BinarySymExprImpl(LHSTYPE lhs, BinaryOperator::Opcode op, RHSTYPE rhs, QualType t)
A symbol representing the result of an expression in the case when we do not know anything about what...
const TypedValueRegion * getRegion() const
Represents a cast expression.
virtual bool VisitMemRegion(const MemRegion *)
const SubRegion * getRegion() const
MemRegion - The root abstract class for all memory regions.
const SymbolCast * getCastSymbol(const SymExpr *Operand, QualType From, QualType To)
bool isDead(SymbolRef sym)
Returns whether or not a symbol has been confirmed dead.
unsigned getCount() const
ASTContext & getContext()
QualType getType() const override
void addSymbolDependency(const SymbolRef Primary, const SymbolRef Dependent)
Add artificial symbol dependency.
QualType getType() const override
const SymbolDerived * getDerivedSymbol(SymbolRef parentSymbol, const TypedValueRegion *R)
virtual QualType getType() const =0
BinarySymExpr(Kind k, BinaryOperator::Opcode op, QualType t)
void markInUse(SymbolRef sym)
Marks a symbol as important to a checker.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
unsigned computeComplexity() const override
void Profile(llvm::FoldingSetNodeID &profile) override
const SymIntExpr * getSymIntExpr(const SymExpr &lhs, BinaryOperator::Opcode op, const llvm::APSInt &rhs, QualType t)
A symbol representing the value stored at a MemRegion.
static bool classof(const SymExpr *SE)
BinaryOperator::Opcode getOpcode() const
SymbolRef getParentSymbol() const
void dumpToStream(raw_ostream &os) const override
static bool classof(const SymExpr *SE)
static unsigned computeOperandComplexity(const llvm::APSInt &Value)
void setReapedStore(StoreRef st)
Set to the value of the symbolic store after StoreManager::removeDeadBindings has been called.
A class responsible for cleaning up unused symbols.
void markElementIndicesLive(const MemRegion *region)
SymbolExtent - Represents the extent (size in bytes) of a bounded region.
void Profile(llvm::FoldingSetNodeID &profile) override
bool isLiveRegion(const MemRegion *region)
unsigned computeComplexity() const override
SymbolVisitor(SymbolVisitor &&)
void dumpToStream(raw_ostream &os) const override
QualType getType() const override
region_iterator region_begin() const
SymbolRegionValue(SymbolID sym, const TypedValueRegion *r)
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 SymbolRefSmallVectorTy * getDependentSymbols(const SymbolRef Primary)
const LocationContext * getLocationContext() const
Template implementation for all binary symbolic expressions.
const SymIntExpr * getSymIntExpr(const SymExpr *lhs, BinaryOperator::Opcode op, const llvm::APSInt &rhs, QualType t)
const SymbolRegionValue * getRegionValueSymbol(const TypedValueRegion *R)
Make a unique symbol for MemRegion R according to its kind.
static const SymExpr * getPointer(const SymExpr *Value)
BinarySymExprImpl< const SymExpr *, const llvm::APSInt &, SymExpr::Kind::SymIntExprKind > SymIntExpr
Represents a symbolic expression like 'x' + 3.
StringRef getKindStr() const override
Get a string representation of the kind of the region.
QualType getType() const override
static void Profile(llvm::FoldingSetNodeID &profile, const SubRegion *R)
void Profile(llvm::FoldingSetNodeID &ID) override
static void Profile(llvm::FoldingSetNodeID &ID, LHSTYPE lhs, BinaryOperator::Opcode op, RHSTYPE rhs, QualType t)
static bool classof(const SymExpr *SE)
StringRef getKindStr() const override
Get a string representation of the kind of the region.
const SymExpr * getOperand() const
const MemRegion * getOriginRegion() const override
Find the region from which this symbol originates.
SymbolCast(const SymExpr *In, QualType From, QualType To)
static void Profile(llvm::FoldingSetNodeID &profile, SymbolRef parent, const TypedValueRegion *r)
const Stmt * getStmt() const
static bool isValidTypeForSymbol(QualType T)
static void Profile(llvm::FoldingSetNodeID &profile, const Stmt *S, QualType T, unsigned Count, const LocationContext *LCtx, const void *SymbolTag)
void Profile(llvm::FoldingSetNodeID &profile) override
QualType getType(const SymExpr *SE) const
void markLive(SymbolRef sym)
Unconditionally marks a symbol as live.
const TypedValueRegion * getRegion() const
static bool classof(const SymExpr *SE)
virtual QualType getValueType() const =0
static void Profile(llvm::FoldingSetNodeID &ID, const SymExpr *In, QualType From, QualType To)
void Profile(llvm::FoldingSetNodeID &profile) override
Stmt - This represents one statement.
void dumpToStream(raw_ostream &os) const override
A symbol representing data which can be stored in a memory location (region).
const SymbolExtent * getExtentSymbol(const SubRegion *R)
const MemRegion * getOriginRegion() const override
Find the region from which this symbol originates.
__device__ __2f16 float bool s
region_iterator region_end() const
StringRef getKindStr() const override
Get a string representation of the kind of the region.
QualType getType() const override
bool isLive(SymbolRef sym)
static const llvm::APSInt * getPointer(const llvm::APSInt &Value)
TypedValueRegion - An abstract class representing regions having a typed value.
SubRegion - A region that subsets another larger region.
virtual bool VisitSymbol(SymbolRef sym)=0
A visitor method invoked by ProgramStateManager::scanReachableSymbols.
static void Profile(llvm::FoldingSetNodeID &profile, const TypedValueRegion *R)
This represents one expression.
static unsigned computeOperandComplexity(const SymExpr *Value)
static bool classof(const SymExpr *SE)
void dumpToStream(raw_ostream &os) const override
A symbol representing the value of a MemRegion whose parent region has symbolic value.
SymbolReaper(const StackFrameContext *Ctx, const Stmt *s, SymbolManager &symmgr, StoreManager &storeMgr)
Construct a reaper object, which removes everything which is not live before we execute statement s i...
static bool canSymbolicate(QualType T)
static bool classof(const SymExpr *SE)
SymbolConjured(SymbolID sym, const Stmt *s, const LocationContext *lctx, QualType t, unsigned count, const void *symbolTag)
SymbolDerived(SymbolID sym, SymbolRef parent, const TypedValueRegion *r)