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/ADT/iterator_range.h"
28#include "llvm/Support/Allocator.h"
38class BasicValueFactory;
47 :
SymbolData(SymbolRegionValueKind, sym), R(r) {
52 LLVM_ATTRIBUTE_RETURNS_NONNULL
56 profile.AddInteger((
unsigned) SymbolRegionValueKind);
57 profile.AddPointer(R);
60 void Profile(llvm::FoldingSetNodeID& profile)
override {
73 return SE->
getKind() == SymbolRegionValueKind;
84 const void *SymbolTag;
88 QualType t,
unsigned count,
const void *symbolTag)
89 :
SymbolData(SymbolConjuredKind, sym), S(
s),
T(t), Count(count),
90 LCtx(lctx), SymbolTag(symbolTag) {
104 const void *
getTag()
const {
return SymbolTag; }
112 static void Profile(llvm::FoldingSetNodeID& profile,
const Stmt *S,
114 const void *SymbolTag) {
115 profile.AddInteger((
unsigned) SymbolConjuredKind);
116 profile.AddPointer(S);
117 profile.AddPointer(LCtx);
119 profile.AddInteger(Count);
120 profile.AddPointer(SymbolTag);
123 void Profile(llvm::FoldingSetNodeID& profile)
override {
124 Profile(profile, S,
T, Count, LCtx, SymbolTag);
129 return SE->
getKind() == SymbolConjuredKind;
141 :
SymbolData(SymbolDerivedKind, sym), parentSymbol(parent), R(r) {
147 LLVM_ATTRIBUTE_RETURNS_NONNULL
149 LLVM_ATTRIBUTE_RETURNS_NONNULL
161 profile.AddInteger((
unsigned) SymbolDerivedKind);
162 profile.AddPointer(r);
163 profile.AddPointer(parent);
166 void Profile(llvm::FoldingSetNodeID& profile)
override {
167 Profile(profile, parentSymbol, R);
172 return SE->
getKind() == SymbolDerivedKind;
188 LLVM_ATTRIBUTE_RETURNS_NONNULL
198 profile.AddInteger((
unsigned) SymbolExtentKind);
199 profile.AddPointer(R);
202 void Profile(llvm::FoldingSetNodeID& profile)
override {
208 return SE->
getKind() == SymbolExtentKind;
227 :
SymbolData(SymbolMetadataKind, sym), R(r), S(
s),
T(t), LCtx(LCtx),
228 Count(count), Tag(tag) {
236 LLVM_ATTRIBUTE_RETURNS_NONNULL
239 LLVM_ATTRIBUTE_RETURNS_NONNULL
242 LLVM_ATTRIBUTE_RETURNS_NONNULL
247 LLVM_ATTRIBUTE_RETURNS_NONNULL
248 const void *
getTag()
const {
return Tag; }
258 unsigned Count,
const void *Tag) {
259 profile.AddInteger((
unsigned)SymbolMetadataKind);
260 profile.AddPointer(R);
261 profile.AddPointer(S);
263 profile.AddPointer(LCtx);
264 profile.AddInteger(Count);
265 profile.AddPointer(Tag);
268 void Profile(llvm::FoldingSetNodeID& profile)
override {
269 Profile(profile, R, S,
T, LCtx, Count, Tag);
274 return SE->
getKind() == SymbolMetadataKind;
290 :
SymExpr(SymbolCastKind), Operand(In), FromTy(From), ToTy(To) {
299 Complexity = 1 + Operand->computeComplexity();
305 LLVM_ATTRIBUTE_RETURNS_NONNULL
312 ID.AddInteger((
unsigned) SymbolCastKind);
324 return SE->
getKind() == SymbolCastKind;
336 :
SymExpr(UnarySymExprKind), Operand(In), Op(Op),
T(
T) {
339 assert((Op == UO_Minus || Op == UO_Not) &&
"non-supported unary expression");
349 Complexity = 1 + Operand->computeComplexity();
361 ID.AddInteger((
unsigned)UnarySymExprKind);
373 return SE->
getKind() == UnarySymExprKind;
402 return k >= BEGIN_BINARYSYMEXPRS && k <= END_BINARYSYMEXPRS;
407 return Value->computeComplexity();
424template <
class LHSTYPE,
class RHSTYPE, SymExpr::Kind ClassKind>
453 static void Profile(llvm::FoldingSetNodeID &
ID, LHSTYPE lhs,
455 ID.AddInteger((
unsigned)ClassKind);
472 SymExpr::Kind::SymIntExprKind>;
476 SymExpr::Kind::IntSymExprKind>;
480 SymExpr::Kind::SymSymExprKind>;
483 using DataSetTy = llvm::FoldingSet<SymExpr>;
484 using SymbolDependTy =
485 llvm::DenseMap<SymbolRef, std::unique_ptr<SymbolRefSmallVectorTy>>;
491 SymbolDependTy SymbolDependencies;
493 unsigned SymbolCounter = 0;
494 llvm::BumpPtrAllocator& BPAlloc;
500 llvm::BumpPtrAllocator& bpalloc)
501 : SymbolDependencies(16), BPAlloc(bpalloc), BV(bv), Ctx(ctx) {}
512 const void *SymbolTag =
nullptr);
517 const void *SymbolTag =
nullptr) {
534 const void *SymbolTag =
nullptr);
540 const llvm::APSInt& rhs,
QualType t);
543 const llvm::APSInt& rhs,
QualType t) {
579 using SymbolSetTy = llvm::DenseSet<SymbolRef>;
580 using SymbolMapTy = llvm::DenseMap<SymbolRef, SymbolStatus>;
581 using RegionSetTy = llvm::DenseSet<const MemRegion *>;
583 SymbolMapTy TheLiving;
584 SymbolSetTy MetadataInUse;
586 RegionSetTy LiveRegionRoots;
591 RegionSetTy LazilyCopiedRegionRoots;
597 llvm::DenseMap<const MemRegion *, unsigned> includedRegionCache;
609 : LCtx(Ctx),
Loc(
s), SymMgr(symmgr), reapedStore(nullptr, storeMgr) {}
617 bool isLive(
const VarRegion *VR,
bool includeStoreBindings =
false)
const;
635 llvm::iterator_range<RegionSetTy::const_iterator>
regions()
const {
636 return LiveRegionRoots;
656 bool isLazilyCopiedRegion(
const MemRegion *region)
const;
660 bool isReadableRegion(
const MemRegion *region);
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.
llvm::DenseMap< const CFGBlock *, unsigned > VisitCount
C Language Family Type Representation.
__device__ __2f16 float __ockl_bool s
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
This represents one expression.
It wraps the AnalysisDeclContext to represent both the call stack with the help of StackFrameContext ...
A (possibly-)qualified type.
It represents a stack frame of the call stack (based on CallEvent).
Stmt - This represents one statement.
Template implementation for all binary symbolic expressions.
static void Profile(llvm::FoldingSetNodeID &ID, LHSTYPE lhs, BinaryOperator::Opcode op, RHSTYPE rhs, QualType t)
BinarySymExprImpl(LHSTYPE lhs, BinaryOperator::Opcode op, RHSTYPE rhs, QualType t)
void Profile(llvm::FoldingSetNodeID &ID) override
void dumpToStream(raw_ostream &os) const override
unsigned computeComplexity() const override
static bool classof(const SymExpr *SE)
Represents a symbolic expression involving a binary operator.
BinarySymExpr(Kind k, BinaryOperator::Opcode op, QualType t)
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)
static const SymExpr * getPointer(const SymExpr *Value)
static const llvm::APSInt * getPointer(const llvm::APSInt &Value)
static bool isLocType(QualType T)
MemRegion - The root abstract class for all memory regions.
SubRegion - A region that subsets another larger region.
static bool isValidTypeForSymbol(QualType T)
virtual QualType getType() const =0
Represents a cast expression.
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
LLVM_ATTRIBUTE_RETURNS_NONNULL const SymExpr * getOperand() const
SymbolCast(const SymExpr *In, QualType From, QualType To)
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
static bool classof(const SymExpr *SE)
StringRef getKindStr() const override
Get a string representation of the kind of the region.
static void Profile(llvm::FoldingSetNodeID &profile, const Stmt *S, QualType T, unsigned Count, const LocationContext *LCtx, const void *SymbolTag)
const void * getTag() const
It might return null.
void dumpToStream(raw_ostream &os) const override
QualType getType() const override
const Stmt * getStmt() const
It might return null.
SymbolConjured(SymbolID sym, const Stmt *s, const LocationContext *lctx, QualType t, unsigned count, const void *symbolTag)
A symbol representing data which can be stored in a memory location (region).
A symbol representing the value of a MemRegion whose parent region has symbolic value.
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 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 bool classof(const SymExpr *SE)
SymbolDerived(SymbolID sym, SymbolRef parent, const TypedValueRegion *r)
SymbolExtent - Represents the extent (size in bytes) of a bounded region.
static bool classof(const SymExpr *SE)
LLVM_ATTRIBUTE_RETURNS_NONNULL const SubRegion * getRegion() const
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
SymbolExtent(SymbolID sym, const SubRegion *r)
const SymbolExtent * getExtentSymbol(const SubRegion *R)
SymbolManager(ASTContext &ctx, BasicValueFactory &bv, llvm::BumpPtrAllocator &bpalloc)
const SymbolDerived * getDerivedSymbol(SymbolRef parentSymbol, 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 SymbolRegionValue * getRegionValueSymbol(const TypedValueRegion *R)
Make a unique symbol for MemRegion R according to its kind.
const SymIntExpr * getSymIntExpr(const SymExpr &lhs, BinaryOperator::Opcode op, const llvm::APSInt &rhs, QualType t)
const SymbolConjured * conjureSymbol(const Stmt *E, const LocationContext *LCtx, QualType T, unsigned VisitCount, const void *SymbolTag=nullptr)
void addSymbolDependency(const SymbolRef Primary, const SymbolRef Dependent)
Add artificial symbol dependency.
BasicValueFactory & getBasicVals()
const SymIntExpr * getSymIntExpr(const SymExpr *lhs, BinaryOperator::Opcode op, const llvm::APSInt &rhs, QualType t)
QualType getType(const SymExpr *SE) const
const SymbolCast * getCastSymbol(const SymExpr *Operand, QualType From, QualType To)
const SymbolConjured * conjureSymbol(const Expr *E, const LocationContext *LCtx, unsigned VisitCount, const void *SymbolTag=nullptr)
const UnarySymExpr * getUnarySymExpr(const SymExpr *operand, UnaryOperator::Opcode op, QualType t)
const SymbolRefSmallVectorTy * getDependentSymbols(const SymbolRef Primary)
static bool canSymbolicate(QualType T)
const SymSymExpr * getSymSymExpr(const SymExpr *lhs, BinaryOperator::Opcode op, const SymExpr *rhs, QualType t)
ASTContext & getContext()
const IntSymExpr * getIntSymExpr(const llvm::APSInt &lhs, BinaryOperator::Opcode op, const SymExpr *rhs, QualType t)
A class responsible for cleaning up unused symbols.
void markLive(SymbolRef sym)
Unconditionally marks a symbol as live.
void markElementIndicesLive(const MemRegion *region)
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 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)
const LocationContext * getLocationContext() const
It might return null.
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
A symbol representing the value stored at a MemRegion.
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
SymbolRegionValue(SymbolID sym, const TypedValueRegion *r)
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)
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
Represents a symbolic expression involving a unary operator.
void dumpToStream(raw_ostream &os) const override
void Profile(llvm::FoldingSetNodeID &ID) override
QualType getType() const override
static bool classof(const SymExpr *SE)
UnaryOperator::Opcode getOpcode() const
unsigned computeComplexity() const override
UnarySymExpr(const SymExpr *In, UnaryOperator::Opcode Op, QualType T)
static void Profile(llvm::FoldingSetNodeID &ID, const SymExpr *In, UnaryOperator::Opcode Op, QualType T)
const SymExpr * getOperand() const
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T