15 #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SYMBOLMANAGER_H 16 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SYMBOLMANAGER_H 25 #include "llvm/ADT/DenseMap.h" 26 #include "llvm/ADT/DenseSet.h" 27 #include "llvm/ADT/FoldingSet.h" 28 #include "llvm/Support/Allocator.h" 38 class BasicValueFactory;
47 :
SymbolData(SymbolRegionValueKind, sym), R(r) {
55 profile.AddInteger((
unsigned) SymbolRegionValueKind);
56 profile.AddPointer(R);
59 void Profile(llvm::FoldingSetNodeID& profile)
override {
70 return SE->
getKind() == SymbolRegionValueKind;
81 const void *SymbolTag;
85 QualType t,
unsigned count,
const void *symbolTag)
86 :
SymbolData(SymbolConjuredKind, sym), S(s), T(t), Count(count),
87 LCtx(lctx), SymbolTag(symbolTag) {
99 const void *
getTag()
const {
return SymbolTag; }
105 static void Profile(llvm::FoldingSetNodeID& profile,
const Stmt *S,
107 const void *SymbolTag) {
108 profile.AddInteger((
unsigned) SymbolConjuredKind);
109 profile.AddPointer(S);
110 profile.AddPointer(LCtx);
112 profile.AddInteger(Count);
113 profile.AddPointer(SymbolTag);
116 void Profile(llvm::FoldingSetNodeID& profile)
override {
117 Profile(profile, S, T, Count, LCtx, SymbolTag);
122 return SE->
getKind() == SymbolConjuredKind;
134 :
SymbolData(SymbolDerivedKind, sym), parentSymbol(parent), R(r) {
150 profile.AddInteger((
unsigned) SymbolDerivedKind);
151 profile.AddPointer(r);
152 profile.AddPointer(parent);
155 void Profile(llvm::FoldingSetNodeID& profile)
override {
156 Profile(profile, parentSymbol, R);
161 return SE->
getKind() == SymbolDerivedKind;
184 profile.AddInteger((
unsigned) SymbolExtentKind);
185 profile.AddPointer(R);
188 void Profile(llvm::FoldingSetNodeID& profile)
override {
194 return SE->
getKind() == SymbolExtentKind;
213 :
SymbolData(SymbolMetadataKind, sym), R(r), S(s), T(t), LCtx(LCtx),
214 Count(count), Tag(tag) {
226 const void *
getTag()
const {
return Tag; }
234 unsigned Count,
const void *Tag) {
235 profile.AddInteger((
unsigned) SymbolMetadataKind);
236 profile.AddPointer(R);
237 profile.AddPointer(S);
239 profile.AddPointer(LCtx);
240 profile.AddInteger(Count);
241 profile.AddPointer(Tag);
244 void Profile(llvm::FoldingSetNodeID& profile)
override {
245 Profile(profile, R, S, T, LCtx, Count, Tag);
250 return SE->
getKind() == SymbolMetadataKind;
266 :
SymExpr(SymbolCastKind), Operand(In), FromTy(From), ToTy(To) {
287 ID.AddInteger((
unsigned) SymbolCastKind);
294 Profile(ID, Operand, FromTy, ToTy);
299 return SE->
getKind() == SymbolCastKind;
325 return k >= BEGIN_BINARYSYMEXPRS && k <= END_BINARYSYMEXPRS;
332 const llvm::APSInt& RHS;
336 const llvm::APSInt &rhs,
QualType t)
344 const llvm::APSInt &
getRHS()
const {
return RHS; }
355 ID.AddInteger((
unsigned) SymIntExprKind);
368 return SE->
getKind() == SymIntExprKind;
374 const llvm::APSInt& LHS;
387 const llvm::APSInt &
getLHS()
const {
return LHS; }
395 static void Profile(llvm::FoldingSetNodeID&
ID,
const llvm::APSInt& lhs,
398 ID.AddInteger((
unsigned) IntSymExprKind);
411 return SE->
getKind() == IntSymExprKind;
441 ID.AddInteger((
unsigned) SymSymExprKind);
454 return SE->
getKind() == SymSymExprKind;
459 using DataSetTy = llvm::FoldingSet<SymExpr>;
460 using SymbolDependTy = llvm::DenseMap<SymbolRef, SymbolRefSmallVectorTy *>;
466 SymbolDependTy SymbolDependencies;
468 unsigned SymbolCounter = 0;
469 llvm::BumpPtrAllocator& BPAlloc;
475 llvm::BumpPtrAllocator& bpalloc)
476 : SymbolDependencies(16), BPAlloc(bpalloc), BV(bv), Ctx(ctx) {}
479 static bool canSymbolicate(
QualType T);
488 const void *SymbolTag =
nullptr);
493 const void *SymbolTag =
nullptr) {
494 return conjureSymbol(E, LCtx, E->
getType(), VisitCount, SymbolTag);
510 const void *SymbolTag =
nullptr);
516 const llvm::APSInt& rhs,
QualType t);
519 const llvm::APSInt& rhs,
QualType t) {
520 return getSymIntExpr(&lhs, op, rhs, t);
523 const IntSymExpr *getIntSymExpr(
const llvm::APSInt& lhs,
553 using SymbolMapTy = llvm::DenseMap<SymbolRef, SymbolStatus>;
556 SymbolMapTy TheLiving;
566 llvm::DenseMap<const MemRegion *, unsigned> includedRegionCache;
578 : LCtx(Ctx), Loc(s), SymMgr(symmgr), reapedStore(nullptr, storeMgr) {}
583 bool isLiveRegion(
const MemRegion *region);
585 bool isLive(
const VarRegion *VR,
bool includeStoreBindings =
false)
const;
615 return !TheDead.empty();
628 return TheDead.count(sym);
632 void markElementIndicesLive(
const MemRegion *region);
656 virtual bool VisitSymbol(
SymbolRef sym) = 0;
664 #endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SYMBOLMANAGER_H
static bool classof(const SymExpr *SE)
TypedValueRegion - An abstract class representing regions having a typed value.
A (possibly-)qualified type.
MemRegion - The root abstract class for all memory regions.
SymbolDerived(SymbolID sym, SymbolRef parent, const TypedValueRegion *r)
unsigned computeComplexity() const override
Stmt - This represents one statement.
C Language Family Type Representation.
static void Profile(llvm::FoldingSetNodeID &profile, const TypedValueRegion *R)
static bool classof(const SymExpr *SE)
virtual QualType getValueType() const =0
const SymExpr * getOperand() const
virtual unsigned computeComplexity() const =0
BasicValueFactory & getBasicVals()
bool isDead(SymbolRef sym) const
Returns whether or not a symbol has been confirmed dead.
SymbolManager(ASTContext &ctx, BasicValueFactory &bv, llvm::BumpPtrAllocator &bpalloc)
ASTContext & getContext()
SymbolCast(const SymExpr *In, QualType From, QualType To)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
static void Profile(llvm::FoldingSetNodeID &profile, SymbolRef parent, const TypedValueRegion *r)
void Profile(llvm::FoldingSetNodeID &profile) override
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...
unsigned getCount() const
void setReapedStore(StoreRef st)
Set to the value of the symbolic store after StoreManager::removeDeadBindings has been called...
static void Profile(llvm::FoldingSetNodeID &ID, const SymExpr *lhs, BinaryOperator::Opcode op, const llvm::APSInt &rhs, QualType t)
SymbolConjured(SymbolID sym, const Stmt *s, const LocationContext *lctx, QualType t, unsigned count, const void *symbolTag)
SymbolExtent(SymbolID sym, const SubRegion *r)
static bool classof(const SymExpr *SE)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
QualType getType(const SymExpr *SE) const
RegionSetTy::const_iterator region_iterator
Represents a symbolic expression like 'x' + 3.
A symbol representing the value of a MemRegion whose parent region has symbolic value.
void Profile(llvm::FoldingSetNodeID &ID) override
virtual QualType getType() const =0
static void Profile(llvm::FoldingSetNodeID &ID, const llvm::APSInt &lhs, BinaryOperator::Opcode op, const SymExpr *rhs, QualType t)
const LocationContext * getLocationContext() const
static bool classof(const SymExpr *SE)
static void Profile(llvm::FoldingSetNodeID &profile, const Stmt *S, QualType T, unsigned Count, const LocationContext *LCtx, const void *SymbolTag)
bool hasDeadSymbols() const
const SymIntExpr * getSymIntExpr(const SymExpr &lhs, BinaryOperator::Opcode op, const llvm::APSInt &rhs, QualType t)
Expr - This represents one expression.
const TypedValueRegion * getRegion() const
void Profile(llvm::FoldingSetNodeID &profile) override
const SubRegion * getRegion() const
Represents a cast expression.
static bool classof(const SymExpr *SE)
IntSymExpr(const llvm::APSInt &lhs, BinaryOperator::Opcode op, const SymExpr *rhs, QualType t)
const SymExpr * getRHS() const
static bool classof(const SymExpr *SE)
virtual bool VisitMemRegion(const MemRegion *region)
const TypedValueRegion * getRegion() const
const SymExpr * getLHS() const
const void * getTag() const
Represents a symbolic expression like 3 - 'x'.
const SymbolConjured * conjureSymbol(const Expr *E, const LocationContext *LCtx, unsigned VisitCount, const void *SymbolTag=nullptr)
void dumpToStream(raw_ostream &os) const override
QualType getType() const override
const llvm::APSInt & getLHS() const
A class responsible for cleaning up unused symbols.
SymIntExpr(const SymExpr *lhs, BinaryOperator::Opcode op, const llvm::APSInt &rhs, QualType t)
unsigned computeComplexity() const override
region_iterator region_end() const
QualType getType() const override
A symbol representing the result of an expression in the case when we do not know anything about what...
static bool isValidTypeForSymbol(QualType T)
SymbolSetTy::const_iterator dead_iterator
A symbol representing the value stored at a MemRegion.
Dataflow Directional Tag Classes.
static void Profile(llvm::FoldingSetNodeID &ID, const SymExpr *In, QualType From, QualType To)
SymbolRegionValue(SymbolID sym, const TypedValueRegion *r)
Represents a symbolic expression involving a binary operator.
const llvm::APSInt & getRHS() const
BinaryOperator::Opcode getOpcode(const SymExpr *SE)
region_iterator region_begin() const
const MemRegion * getOriginRegion() const override
Find the region from which this symbol originates.
QualType getType() const override
static bool classof(const SymExpr *SE)
void Profile(llvm::FoldingSetNodeID &ID) override
unsigned computeComplexity() const override
dead_iterator dead_begin() const
const SymExpr * getRHS() const
SymbolVisitor(SymbolVisitor &&)
static bool classof(const SymExpr *SE)
SubRegion - A region that subsets another larger region.
void Profile(llvm::FoldingSetNodeID &ID) override
const Stmt * getStmt() const
dead_iterator dead_end() const
static void Profile(llvm::FoldingSetNodeID &profile, const SubRegion *R)
const MemRegion * getOriginRegion() const override
Find the region from which this symbol originates.
BinaryOperator::Opcode getOpcode() const
SymbolRef getParentSymbol() const
SymSymExpr(const SymExpr *lhs, BinaryOperator::Opcode op, const SymExpr *rhs, QualType t)
void Profile(llvm::FoldingSetNodeID &profile) override
static bool classof(const SymExpr *SE)
BinarySymExpr(Kind k, BinaryOperator::Opcode op, QualType t)
SymbolExtent - Represents the extent (size in bytes) of a bounded region.
void Profile(llvm::FoldingSetNodeID &profile) override
void Profile(llvm::FoldingSetNodeID &ID) override
unsigned computeComplexity() const override
Represents a symbolic expression like 'x' + 'y'.
A symbol representing data which can be stored in a memory location (region).
const SymExpr * getLHS() const
static void Profile(llvm::FoldingSetNodeID &ID, const SymExpr *lhs, BinaryOperator::Opcode op, const SymExpr *rhs, QualType t)