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"
29 #include "llvm/Support/DataTypes.h"
33 class StackFrameContext;
36 class BasicValueFactory;
38 class TypedValueRegion;
47 :
SymbolData(SymbolRegionValueKind, sym), R(r) {}
52 profile.AddInteger((
unsigned) SymbolRegionValueKind);
53 profile.AddPointer(R);
56 void Profile(llvm::FoldingSetNodeID& profile)
override {
67 return SE->
getKind() == SymbolRegionValueKind;
78 const void *SymbolTag;
82 QualType t,
unsigned count,
const void *symbolTag)
83 :
SymbolData(SymbolConjuredKind, sym), S(s), T(t), Count(count),
84 LCtx(lctx), SymbolTag(symbolTag) {}
88 const void *
getTag()
const {
return SymbolTag; }
94 static void Profile(llvm::FoldingSetNodeID& profile,
const Stmt *S,
96 const void *SymbolTag) {
97 profile.AddInteger((
unsigned) SymbolConjuredKind);
98 profile.AddPointer(S);
99 profile.AddPointer(LCtx);
101 profile.AddInteger(Count);
102 profile.AddPointer(SymbolTag);
105 void Profile(llvm::FoldingSetNodeID& profile)
override {
106 Profile(profile, S, T, Count, LCtx, SymbolTag);
111 return SE->
getKind() == SymbolConjuredKind;
123 :
SymbolData(SymbolDerivedKind, sym), parentSymbol(parent), R(r) {}
135 profile.AddInteger((
unsigned) SymbolDerivedKind);
136 profile.AddPointer(r);
137 profile.AddPointer(parent);
140 void Profile(llvm::FoldingSetNodeID& profile)
override {
141 Profile(profile, parentSymbol, R);
146 return SE->
getKind() == SymbolDerivedKind;
167 profile.AddInteger((
unsigned) SymbolExtentKind);
168 profile.AddPointer(R);
171 void Profile(llvm::FoldingSetNodeID& profile)
override {
177 return SE->
getKind() == SymbolExtentKind;
193 unsigned count,
const void *tag)
194 :
SymbolData(SymbolMetadataKind, sym), R(r), S(s), T(t), Count(count), Tag(tag) {}
199 const void *
getTag()
const {
return Tag; }
208 profile.AddInteger((
unsigned) SymbolMetadataKind);
209 profile.AddPointer(R);
210 profile.AddPointer(S);
212 profile.AddInteger(Count);
213 profile.AddPointer(Tag);
216 void Profile(llvm::FoldingSetNodeID& profile)
override {
217 Profile(profile, R, S, T, Count, Tag);
222 return SE->
getKind() == SymbolMetadataKind;
236 SymExpr(SymbolCastKind), Operand(In), FromTy(From), ToTy(To) { }
246 ID.AddInteger((
unsigned) SymbolCastKind);
253 Profile(ID, Operand, FromTy, ToTy);
258 return SE->
getKind() == SymbolCastKind;
281 return k >= BEGIN_BINARYSYMEXPRS && k <= END_BINARYSYMEXPRS;
288 const llvm::APSInt& RHS;
292 const llvm::APSInt& rhs,
QualType t)
293 :
BinarySymExpr(SymIntExprKind, op, t), LHS(lhs), RHS(rhs) {}
298 const llvm::APSInt &
getRHS()
const {
return RHS; }
303 ID.AddInteger((
unsigned) SymIntExprKind);
316 return SE->
getKind() == SymIntExprKind;
322 const llvm::APSInt& LHS;
328 :
BinarySymExpr(IntSymExprKind, op, t), LHS(lhs), RHS(rhs) {}
333 const llvm::APSInt &
getLHS()
const {
return LHS; }
335 static void Profile(llvm::FoldingSetNodeID&
ID,
const llvm::APSInt& lhs,
338 ID.AddInteger((
unsigned) IntSymExprKind);
351 return SE->
getKind() == IntSymExprKind;
363 :
BinarySymExpr(SymSymExprKind, op, t), LHS(lhs), RHS(rhs) {}
372 ID.AddInteger((
unsigned) SymSymExprKind);
385 return SE->
getKind() == SymSymExprKind;
390 typedef llvm::FoldingSet<SymExpr> DataSetTy;
391 typedef llvm::DenseMap<SymbolRef, SymbolRefSmallVectorTy*> SymbolDependTy;
396 SymbolDependTy SymbolDependencies;
397 unsigned SymbolCounter;
398 llvm::BumpPtrAllocator& BPAlloc;
404 llvm::BumpPtrAllocator& bpalloc)
405 : SymbolDependencies(16), SymbolCounter(0),
406 BPAlloc(bpalloc), BV(bv), Ctx(ctx) {}
419 const void *SymbolTag =
nullptr);
424 const void *SymbolTag =
nullptr) {
439 const void *SymbolTag =
nullptr);
445 const llvm::APSInt& rhs,
QualType t);
448 const llvm::APSInt& rhs,
QualType t) {
482 typedef llvm::DenseMap<SymbolRef, SymbolStatus> SymbolMapTy;
485 SymbolMapTy TheLiving;
495 llvm::DenseMap<const MemRegion *, unsigned> includedRegionCache;
507 : LCtx(Ctx),
Loc(s), SymMgr(symmgr),
508 reapedStore(nullptr, storeMgr) {}
515 bool isLive(
const VarRegion *VR,
bool includeStoreBindings =
false)
const;
544 return !TheDead.empty();
556 return TheDead.count(sym);
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.
void markLive(SymbolRef sym)
Unconditionally marks a symbol as live.
const llvm::APSInt & getRHS() const
SymbolDerived(SymbolID sym, SymbolRef parent, const TypedValueRegion *r)
bool hasDeadSymbols() const
const SymExpr * getLHS() const
bool maybeDead(SymbolRef sym)
If a symbol is known to be live, marks the symbol as live.
const IntSymExpr * getIntSymExpr(const llvm::APSInt &lhs, BinaryOperator::Opcode op, const SymExpr *rhs, QualType t)
static void Profile(llvm::FoldingSetNodeID &profile, const TypedValueRegion *R)
static bool classof(const SymExpr *SE)
const SymExpr * getRHS() const
void dumpToStream(raw_ostream &os) const override
BasicValueFactory & getBasicVals()
void dumpToStream(raw_ostream &os) const override
SymbolManager(ASTContext &ctx, BasicValueFactory &bv, llvm::BumpPtrAllocator &bpalloc)
SymbolRef getParentSymbol() const
const SymbolRefSmallVectorTy * getDependentSymbols(const SymbolRef Primary)
ASTContext & getContext()
const SymbolDerived * getDerivedSymbol(SymbolRef parentSymbol, const TypedValueRegion *R)
SymbolCast(const SymExpr *In, QualType From, QualType To)
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 ...
static void Profile(llvm::FoldingSetNodeID &profile, SymbolRef parent, const TypedValueRegion *r)
void Profile(llvm::FoldingSetNodeID &profile) override
void markElementIndicesLive(const MemRegion *region)
static bool canSymbolicate(QualType T)
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...
void addSymbolDependency(const SymbolRef Primary, const SymbolRef Dependent)
Add artificial symbol dependency.
void setReapedStore(StoreRef st)
Set to the value of the symbolic store after StoreManager::removeDeadBindings has been called...
const SymExpr * getLHS() const
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)
bool isLiveRegion(const MemRegion *region)
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)
const SubRegion * getRegion() const
Represents a symbolic expression like 'x' + 3.
dead_iterator dead_begin() const
A symbol representing the value of a MemRegion whose parent region has symbolic value.
const LocationContext * getLocationContext() const
void Profile(llvm::FoldingSetNodeID &ID) override
QualType getType() const 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 Stmt * getStmt() 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)
QualType getType(const SymExpr *SE) const
const SymIntExpr * getSymIntExpr(const SymExpr &lhs, BinaryOperator::Opcode op, const llvm::APSInt &rhs, QualType t)
bool isDead(SymbolRef sym) const
Returns whether or not a symbol has been confirmed dead.
Expr - This represents one expression.
void Profile(llvm::FoldingSetNodeID &profile) override
SymbolSetTy::const_iterator dead_iterator
Represents a cast expression.
const TypedValueRegion * getRegion() const
static bool classof(const SymExpr *SE)
const TypedValueRegion * getRegion() const
RegionSetTy::const_iterator region_iterator
const SymExpr * getRHS() const
const void * getTag() const
IntSymExpr(const llvm::APSInt &lhs, BinaryOperator::Opcode op, const SymExpr *rhs, QualType t)
static bool classof(const SymExpr *SE)
const SymbolCast * getCastSymbol(const SymExpr *Operand, QualType From, QualType To)
virtual bool VisitMemRegion(const MemRegion *region)
const SymSymExpr * getSymSymExpr(const SymExpr *lhs, BinaryOperator::Opcode op, const SymExpr *rhs, QualType t)
QualType getType() const override
region_iterator region_begin() const
const SymbolRegionValue * getRegionValueSymbol(const TypedValueRegion *R)
Make a unique symbol for MemRegion R according to its kind.
const SymbolMetadata * getMetadataSymbol(const MemRegion *R, const Stmt *S, QualType T, unsigned VisitCount, const void *SymbolTag=nullptr)
Creates a metadata symbol associated with a specific region.
QualType getType() const override
Represents a symbolic expression like 3 - 'x'.
const SymbolConjured * conjureSymbol(const Expr *E, const LocationContext *LCtx, unsigned VisitCount, const void *SymbolTag=nullptr)
dead_iterator dead_end() const
void dumpToStream(raw_ostream &os) const override
QualType getType() const override
A class responsible for cleaning up unused symbols.
SymIntExpr(const SymExpr *lhs, BinaryOperator::Opcode op, const llvm::APSInt &rhs, QualType t)
QualType getType() const override
A symbol representing the result of an expression in the case when we do not know anything about what...
unsigned getCount() const
void dumpToStream(raw_ostream &os) const override
A symbol representing the value stored at a MemRegion.
static void Profile(llvm::FoldingSetNodeID &ID, const SymExpr *In, QualType From, QualType To)
SymbolRegionValue(SymbolID sym, const TypedValueRegion *r)
virtual bool VisitSymbol(SymbolRef sym)=0
A visitor method invoked by ProgramStateManager::scanReachableSymbols.
Represents a symbolic expression involving a binary operator.
const llvm::APSInt & getLHS() const
const MemRegion * getOriginRegion() const override
Find the region from which this symbol originates.
QualType getType() const override
static bool classof(const SymExpr *SE)
detail::InMemoryDirectory::const_iterator E
void Profile(llvm::FoldingSetNodeID &ID) override
const SymbolConjured * conjureSymbol(const Stmt *E, const LocationContext *LCtx, QualType T, unsigned VisitCount, const void *SymbolTag=nullptr)
virtual void dumpToStream(raw_ostream &os) const
SymbolVisitor(SymbolVisitor &&)
region_iterator region_end() const
static bool classof(const SymExpr *SE)
SubRegion - A region that subsets another larger region.
void Profile(llvm::FoldingSetNodeID &ID) override
BinaryOperator::Opcode getOpcode() const
static raw_ostream & operator<<(raw_ostream &os, const clang::ento::MemRegion *R)
static void Profile(llvm::FoldingSetNodeID &profile, const SubRegion *R)
const MemRegion * getOriginRegion() const override
Find the region from which this symbol originates.
const SymbolExtent * getExtentSymbol(const SubRegion *R)
SymSymExpr(const SymExpr *lhs, BinaryOperator::Opcode op, const SymExpr *rhs, QualType t)
void Profile(llvm::FoldingSetNodeID &profile) override
static bool classof(const SymExpr *SE)
void dumpToStream(raw_ostream &os) const override
BinarySymExpr(Kind k, BinaryOperator::Opcode op, QualType t)
void dumpToStream(raw_ostream &os) const override
const SymExpr * getOperand() const
void dumpToStream(raw_ostream &os) const override
SymbolExtent - Represents the extent (size in bytes) of a bounded region.
void Profile(llvm::FoldingSetNodeID &profile) override
void Profile(llvm::FoldingSetNodeID &ID) override
void dumpToStream(raw_ostream &os) const override
Represents a symbolic expression like 'x' + 'y'.
A symbol representing data which can be stored in a memory location (region).
bool isLive(SymbolRef sym)
static void Profile(llvm::FoldingSetNodeID &ID, const SymExpr *lhs, BinaryOperator::Opcode op, const SymExpr *rhs, QualType t)