14#ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SYMBOLMANAGER_H
15#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/ADT/ImmutableSet.h"
29#include "llvm/ADT/iterator_range.h"
30#include "llvm/Support/Allocator.h"
55 LLVM_ATTRIBUTE_RETURNS_NONNULL
60 profile.AddPointer(R);
63 void Profile(llvm::FoldingSetNodeID& profile)
override {
87 const void *SymbolTag;
91 QualType t,
unsigned count,
const void *symbolTag)
93 SymbolTag(symbolTag) {
106 const void *
getTag()
const {
return SymbolTag; }
116 const void *SymbolTag) {
119 profile.AddPointer(SF);
121 profile.AddInteger(Count);
122 profile.AddPointer(SymbolTag);
125 void Profile(llvm::FoldingSetNodeID& profile)
override {
126 Profile(profile, Elem, SF, T, Count, SymbolTag);
150 LLVM_ATTRIBUTE_RETURNS_NONNULL
152 LLVM_ATTRIBUTE_RETURNS_NONNULL
165 profile.AddPointer(r);
166 profile.AddPointer(parent);
169 void Profile(llvm::FoldingSetNodeID& profile)
override {
170 Profile(profile, parentSymbol, R);
192 LLVM_ATTRIBUTE_RETURNS_NONNULL
203 profile.AddPointer(R);
206 void Profile(llvm::FoldingSetNodeID& profile)
override {
232 const StackFrame *SF,
unsigned count,
const void *tag)
243 LLVM_ATTRIBUTE_RETURNS_NONNULL
246 LLVM_ATTRIBUTE_RETURNS_NONNULL
249 LLVM_ATTRIBUTE_RETURNS_NONNULL
254 LLVM_ATTRIBUTE_RETURNS_NONNULL
255 const void *
getTag()
const {
return Tag; }
265 unsigned Count,
const void *Tag) {
267 profile.AddPointer(R);
268 profile.AddPointer(S);
270 profile.AddPointer(SF);
271 profile.AddInteger(Count);
272 profile.AddPointer(Tag);
275 void Profile(llvm::FoldingSetNodeID& profile)
override {
276 Profile(profile, R, S, T, SF, Count, Tag);
307 Complexity = 1 + Operand->computeComplexity();
313 LLVM_ATTRIBUTE_RETURNS_NONNULL
318 static void Profile(llvm::FoldingSetNodeID& ID,
326 void Profile(llvm::FoldingSetNodeID& ID)
override {
327 Profile(ID, Operand, FromTy, ToTy);
348 assert((Op == UO_Minus || Op == UO_Not) &&
"non-supported unary expression");
359 Complexity = 1 + Operand->computeComplexity();
377 void Profile(llvm::FoldingSetNodeID &ID)
override {
394 :
SymExpr(k, Sym), Op(op), T(t) {
412 return K >= BEGIN_BINARYSYMEXPRS && K <= END_BINARYSYMEXPRS;
417 return Value->computeComplexity();
432template <
class LHSTYPE,
class RHSTYPE, SymExpr::Kind ClassK>
462 static void Profile(llvm::FoldingSetNodeID &ID, LHSTYPE lhs,
471 void Profile(llvm::FoldingSetNodeID &ID)
override {
483 SymExpr::Kind::SymIntExprKind>;
487 SymExpr::Kind::IntSymExprKind>;
491 SymExpr::Kind::SymSymExprKind>;
495 llvm::BumpPtrAllocator &Alloc;
500 template <
class SymT,
typename... ArgsT> SymT *
make(ArgsT &&...Args) {
501 return new (Alloc) SymT(nextID(), std::forward<ArgsT>(Args)...);
505 SymbolID nextID() {
return NextSymbolID++; }
509 using DataSetTy = llvm::FoldingSet<SymExpr>;
510 using SymbolDependTy =
511 llvm::DenseMap<SymbolRef, std::unique_ptr<SymbolRefSmallVectorTy>>;
517 SymbolDependTy SymbolDependencies;
525 llvm::BumpPtrAllocator &bpalloc)
526 : SymbolDependencies(16), Alloc(bpalloc), BV(bv), Ctx(ctx) {}
533 template <
typename SymExprT,
typename... Args>
539 const void *SymbolTag =
nullptr) {
566 using SymbolSetTy = llvm::DenseSet<SymbolRef>;
567 using SymbolMapTy = llvm::DenseMap<SymbolRef, SymbolStatus>;
568 using RegionSetTy = llvm::DenseSet<const MemRegion *>;
570 SymbolMapTy TheLiving;
571 SymbolSetTy MetadataInUse;
573 RegionSetTy LiveRegionRoots;
578 RegionSetTy LazilyCopiedRegionRoots;
584 llvm::DenseMap<const MemRegion *, unsigned> includedRegionCache;
595 : SF(SF), Loc(s), SymMgr(symmgr), reapedStore(
nullptr, storeMgr) {}
603 bool isLive(
const VarRegion *VR,
bool includeStoreBindings =
false)
const;
621 llvm::iterator_range<RegionSetTy::const_iterator>
regions()
const {
622 return LiveRegionRoots;
642 bool isLazilyCopiedRegion(
const MemRegion *region)
const;
646 bool isReadableRegion(
const MemRegion *region);
674template <
typename T,
typename... Args>
676 llvm::FoldingSetNodeID profile;
677 T::Profile(profile, args...);
679 SymExpr *SD = DataSet.FindNodeOrInsertPos(profile, InsertPos);
681 SD = Alloc.make<T>(std::forward<Args>(args)...);
682 DataSet.InsertNode(SD, InsertPos);
697struct llvm::ImutContainerInfo<
clang::ento::SymbolRef>
This file defines AnalysisDeclContext, a class that manages the analysis context data for context sen...
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
BinaryOperatorKind Opcode
This represents one expression.
A (possibly-)qualified type.
It represents a stack frame of the call stack.
Stmt - This represents one statement.
A safe wrapper around APSInt objects allocated and owned by BasicValueFactory.
Template implementation for all binary symbolic expressions.
static constexpr bool classof(Kind K)
unsigned computeComplexity() const override
static bool classof(const SymExpr *SE)
void Profile(llvm::FoldingSetNodeID &ID) override
static constexpr Kind ClassKind
friend class SymExprAllocator
static void Profile(llvm::FoldingSetNodeID &ID, LHSTYPE lhs, BinaryOperator::Opcode op, RHSTYPE rhs, QualType t)
void dumpToStream(raw_ostream &os) const override
QualType getType() const override
BinaryOperator::Opcode getOpcode() const
static unsigned computeOperandComplexity(const SymExpr *Value)
static void dumpToStreamImpl(raw_ostream &os, const SymExpr *Value)
static bool classof(const SymExpr *SE)
static unsigned computeOperandComplexity(const llvm::APSInt &Value)
BinarySymExpr(SymbolID Sym, Kind k, BinaryOperator::Opcode op, QualType t)
static constexpr bool classof(Kind K)
static const llvm::APSInt * getPointer(APSIntPtr Value)
static const SymExpr * getPointer(const SymExpr *Value)
static bool isLocType(QualType T)
MemRegion - The root abstract class for all memory regions.
SubRegion - A region that subsets another larger region.
SymT * make(ArgsT &&...Args)
SymExprAllocator(llvm::BumpPtrAllocator &Alloc)
static bool isValidTypeForSymbol(QualType T)
SymExpr(Kind k, SymbolID Sym)
virtual QualType getType() const =0
SymbolID getSymbolID() const
Get a unique identifier for this symbol.
static bool classof(const SymExpr *SE)
static void Profile(llvm::FoldingSetNodeID &ID, const SymExpr *In, QualType From, QualType To)
QualType getType() const override
void Profile(llvm::FoldingSetNodeID &ID) override
void dumpToStream(raw_ostream &os) const override
static constexpr Kind ClassKind
LLVM_ATTRIBUTE_RETURNS_NONNULL const SymExpr * getOperand() const
friend class SymExprAllocator
static constexpr bool classof(Kind K)
unsigned computeComplexity() const override
A symbol representing the result of an expression in the case when we do not know anything about what...
void Profile(llvm::FoldingSetNodeID &profile) override
unsigned getCount() const
const Stmt * getStmt() const
static bool classof(const SymExpr *SE)
static void Profile(llvm::FoldingSetNodeID &profile, ConstCFGElementRef Elem, const StackFrame *SF, QualType T, unsigned Count, const void *SymbolTag)
StringRef getKindStr() const override
Get a string representation of the kind of the region.
ConstCFGElementRef getCFGElementRef() const
static constexpr Kind ClassKind
const void * getTag() const
It might return null.
static constexpr bool classof(Kind K)
void dumpToStream(raw_ostream &os) const override
QualType getType() const override
friend class SymExprAllocator
SymbolData(Kind k, SymbolID sym)
LLVM_ATTRIBUTE_RETURNS_NONNULL SymbolRef getParentSymbol() const
StringRef getKindStr() const override
Get a string representation of the kind of the region.
void dumpToStream(raw_ostream &os) const override
const MemRegion * getOriginRegion() const override
Find the region from which this symbol originates.
static constexpr bool classof(Kind K)
static void Profile(llvm::FoldingSetNodeID &profile, SymbolRef parent, const TypedValueRegion *r)
void Profile(llvm::FoldingSetNodeID &profile) override
QualType getType() const override
LLVM_ATTRIBUTE_RETURNS_NONNULL const TypedValueRegion * getRegion() const
static constexpr Kind ClassKind
static bool classof(const SymExpr *SE)
friend class SymExprAllocator
static bool classof(const SymExpr *SE)
LLVM_ATTRIBUTE_RETURNS_NONNULL const SubRegion * getRegion() const
static constexpr bool classof(Kind K)
void dumpToStream(raw_ostream &os) const override
QualType getType() const override
static void Profile(llvm::FoldingSetNodeID &profile, const SubRegion *R)
StringRef getKindStr() const override
Get a string representation of the kind of the region.
void Profile(llvm::FoldingSetNodeID &profile) override
static constexpr Kind ClassKind
friend class SymExprAllocator
SymbolManager(ASTContext &ctx, BasicValueFactory &bv, llvm::BumpPtrAllocator &bpalloc)
const SymExprT * acquire(Args &&...args)
Create or retrieve a SymExpr of type SymExprT for the given arguments.
void addSymbolDependency(const SymbolRef Primary, const SymbolRef Dependent)
Add artificial symbol dependency.
BasicValueFactory & getBasicVals()
QualType getType(const SymExpr *SE) const
const SymbolConjured * conjureSymbol(ConstCFGElementRef Elem, const StackFrame *SF, QualType T, unsigned VisitCount, const void *SymbolTag=nullptr)
const SymbolRefSmallVectorTy * getDependentSymbols(const SymbolRef Primary)
static bool canSymbolicate(QualType T)
ASTContext & getContext()
const StackFrame * getStackFrame() const
It might return null.
void markLive(SymbolRef sym)
Unconditionally marks a symbol as live.
void markElementIndicesLive(const MemRegion *region)
bool isDead(SymbolRef sym)
Returns whether or not a symbol has been confirmed dead.
void markInUse(SymbolRef sym)
Marks a symbol as important to a checker.
bool isLiveRegion(const MemRegion *region)
void markLazilyCopied(const MemRegion *region)
SymbolReaper(const StackFrame *SF, const Stmt *s, SymbolManager &symmgr, StoreManager &storeMgr)
Construct a reaper object, which removes everything which is not live before we execute statements in...
void setReapedStore(StoreRef st)
Set to the value of the symbolic store after StoreManager::removeDeadBindings has been called.
bool isLive(SymbolRef sym)
llvm::iterator_range< RegionSetTy::const_iterator > regions() const
void dumpToStream(raw_ostream &os) const override
const MemRegion * getOriginRegion() const override
Find the region from which this symbol originates.
void Profile(llvm::FoldingSetNodeID &profile) override
LLVM_ATTRIBUTE_RETURNS_NONNULL const TypedValueRegion * getRegion() const
static void Profile(llvm::FoldingSetNodeID &profile, const TypedValueRegion *R)
QualType getType() const override
StringRef getKindStr() const override
Get a string representation of the kind of the region.
static bool classof(const SymExpr *SE)
friend class SymExprAllocator
static constexpr Kind ClassKind
static constexpr bool classof(Kind K)
virtual bool VisitMemRegion(const MemRegion *)
SymbolVisitor(const SymbolVisitor &)=default
SymbolVisitor(SymbolVisitor &&)
SymbolVisitor & operator=(SymbolVisitor &&)=delete
SymbolVisitor & operator=(const SymbolVisitor &)=delete
virtual bool VisitSymbol(SymbolRef sym)=0
A visitor method invoked by ProgramStateManager::scanReachableSymbols.
TypedValueRegion - An abstract class representing regions having a typed value.
virtual QualType getValueType() const =0
void dumpToStream(raw_ostream &os) const override
void Profile(llvm::FoldingSetNodeID &ID) override
static constexpr bool classof(Kind K)
QualType getType() const override
static constexpr Kind ClassKind
static bool classof(const SymExpr *SE)
UnaryOperator::Opcode getOpcode() const
unsigned computeComplexity() const override
static void Profile(llvm::FoldingSetNodeID &ID, const SymExpr *In, UnaryOperator::Opcode Op, QualType T)
friend class SymExprAllocator
const SymExpr * getOperand() const
SmallVector< SymbolRef, 2 > SymbolRefSmallVectorTy
BinarySymExprImpl< APSIntPtr, const SymExpr *, SymExpr::Kind::IntSymExprKind > IntSymExpr
Represents a symbolic expression like 3 - 'x'.
const SymExpr * SymbolRef
BinarySymExprImpl< const SymExpr *, const SymExpr *, SymExpr::Kind::SymSymExprKind > SymSymExpr
Represents a symbolic expression like 'x' + 'y'.
BinarySymExprImpl< const SymExpr *, APSIntPtr, SymExpr::Kind::SymIntExprKind > SymIntExpr
Represents a symbolic expression like 'x' + 3.
The JSON file list parser is used to communicate input to InstallAPI.
CFGBlock::ConstCFGElementRef ConstCFGElementRef
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
@ Dependent
Parse the block as a dependent block, which may be used in some template instantiations but not other...
U cast(CodeGen::Address addr)
value_type_ref key_type_ref
static key_type_ref KeyOfValue(value_type_ref D)
static data_type_ref DataOfValue(value_type_ref)
static bool isEqual(clang::ento::SymbolRef LHS, clang::ento::SymbolRef RHS)
static bool isLess(clang::ento::SymbolRef LHS, clang::ento::SymbolRef RHS)
static bool isDataEqual(data_type_ref, data_type_ref)
clang::ento::SymbolRef value_type
clang::ento::SymbolRef value_type_ref