15 #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SYMBOLMANAGER_H
16 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SYMBOLMANAGER_H
23 #include "llvm/ADT/DenseMap.h"
24 #include "llvm/ADT/DenseSet.h"
25 #include "llvm/ADT/FoldingSet.h"
26 #include "llvm/Support/Allocator.h"
27 #include "llvm/Support/DataTypes.h"
31 class StackFrameContext;
34 class BasicValueFactory;
37 class TypedValueRegion;
42 class SymExpr :
public llvm::FoldingSetNode {
43 virtual void anchor();
64 virtual void dump()
const;
69 virtual void Profile(llvm::FoldingSetNodeID& profile) = 0;
105 void anchor()
override;
135 profile.AddPointer(R);
138 void Profile(llvm::FoldingSetNodeID& profile)
override {
159 const void *SymbolTag;
164 const void *symbolTag)
167 SymbolTag(symbolTag) {}
171 const void *
getTag()
const {
return SymbolTag; }
177 static void Profile(llvm::FoldingSetNodeID& profile,
const Stmt *S,
179 const void *SymbolTag) {
181 profile.AddPointer(S);
182 profile.AddPointer(LCtx);
184 profile.AddInteger(Count);
185 profile.AddPointer(SymbolTag);
188 void Profile(llvm::FoldingSetNodeID& profile)
override {
189 Profile(profile, S, T, Count, LCtx, SymbolTag);
218 profile.AddPointer(r);
219 profile.AddPointer(parent);
222 void Profile(llvm::FoldingSetNodeID& profile)
override {
223 Profile(profile, parentSymbol, R);
250 profile.AddPointer(R);
253 void Profile(llvm::FoldingSetNodeID& profile)
override {
275 unsigned count,
const void *tag)
281 const void *
getTag()
const {
return Tag; }
291 profile.AddPointer(R);
292 profile.AddPointer(S);
294 profile.AddInteger(Count);
295 profile.AddPointer(Tag);
298 void Profile(llvm::FoldingSetNodeID& profile)
override {
299 Profile(profile, R, S, T, Count, Tag);
335 Profile(ID, Operand, FromTy, ToTy);
370 const llvm::APSInt& RHS;
374 const llvm::APSInt& rhs,
QualType t)
380 const llvm::APSInt &
getRHS()
const {
return RHS; }
404 const llvm::APSInt& LHS;
415 const llvm::APSInt &
getLHS()
const {
return LHS; }
417 static void Profile(llvm::FoldingSetNodeID&
ID,
const llvm::APSInt& lhs,
472 typedef llvm::FoldingSet<SymExpr> DataSetTy;
473 typedef llvm::DenseMap<SymbolRef, SymbolRefSmallVectorTy*> SymbolDependTy;
478 SymbolDependTy SymbolDependencies;
479 unsigned SymbolCounter;
480 llvm::BumpPtrAllocator& BPAlloc;
486 llvm::BumpPtrAllocator& bpalloc)
487 : SymbolDependencies(16), SymbolCounter(0),
488 BPAlloc(bpalloc), BV(bv), Ctx(ctx) {}
501 const void *SymbolTag =
nullptr);
506 const void *SymbolTag =
nullptr) {
521 const void *SymbolTag =
nullptr);
527 const llvm::APSInt& rhs,
QualType t);
530 const llvm::APSInt& rhs,
QualType t) {
564 typedef llvm::DenseMap<SymbolRef, SymbolStatus> SymbolMapTy;
567 SymbolMapTy TheLiving;
577 llvm::DenseMap<const MemRegion *, unsigned> includedRegionCache;
589 : LCtx(Ctx),
Loc(s), SymMgr(symmgr),
590 reapedStore(nullptr, storeMgr) {}
597 bool isLive(
const VarRegion *VR,
bool includeStoreBindings =
false)
const;
626 return !TheDead.empty();
638 return TheDead.count(sym);
SmallVector< SymbolRef, 2 > SymbolRefSmallVectorTy
static bool classof(const SymExpr *SE)
TypedValueRegion - An abstract class representing regions having a typed value.
MemRegion - The root abstract class for all memory regions.
bool operator==(const symbol_iterator &X) const
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
const SymExpr * SymbolRef
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)
symbol_iterator & operator++()
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)
Symbolic value. These values used to capture symbolic execution of the program.
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.
SymbolID getSymbolID() const
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
unsigned computeComplexity() const
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...
bool operator!=(const symbol_iterator &X) const
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)
virtual void dump() const
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
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
ID
Defines the set of possible language-specific address spaces.
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.
void Profile(llvm::FoldingSetNodeID &profile) override
SymbolSetTy::const_iterator dead_iterator
static bool classof(const SymExpr *SE)
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)
virtual void Profile(llvm::FoldingSetNodeID &profile)=0
QualType getType() const override
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
static symbol_iterator symbol_end()
SymbolData(Kind k, SymbolID sym)
QualType getType() const override
static bool classof(const SymExpr *SE)
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
region_iterator region_end() const
static bool classof(const SymExpr *SE)
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 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
symbol_iterator symbol_begin() const
BinarySymExpr(Kind k, BinaryOperator::Opcode op, QualType t)
void dumpToStream(raw_ostream &os) const override
const SymExpr * operator*()
const SymExpr * getOperand() const
void dumpToStream(raw_ostream &os) const override
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)
Iterator over symbols that the current symbol depends on.