24#include "llvm/Support/Compiler.h"
25#include "llvm/Support/ErrorHandling.h"
26#include "llvm/Support/raw_ostream.h"
32void SymExpr::anchor() {}
44 Sym->dumpToStream(
OS);
49 const llvm::APSInt &
Value) {
50 if (
Value.isUnsigned())
54 if (
Value.isUnsigned())
64 os <<
'(' << ToTy <<
") (";
65 Operand->dumpToStream(os);
74 Operand->dumpToStream(os);
81 if (Elem.getParent() ==
nullptr ||
82 Elem.getIndexInBlock() >= Elem.getParent()->size())
84 switch (Elem->getKind()) {
87 return Init->getInit();
93 return Elem->castAs<
CFGScopeEnd>().getTriggerStmt();
127 os <<
", S" << S->getID(SF->getDecl()->getASTContext());
130 os <<
", #" << Count <<
'}';
146void SymbolData::anchor() {}
152void SymExpr::symbol_iterator::expand(
const SymExpr *SE) {
154 case SymExpr::SymbolRegionValueKind:
155 case SymExpr::SymbolConjuredKind:
156 case SymExpr::SymbolDerivedKind:
157 case SymExpr::SymbolExtentKind:
158 case SymExpr::SymbolMetadataKind:
160 case SymExpr::SymbolCastKind:
163 case SymExpr::UnarySymExprKind:
166 case SymExpr::SymIntExprKind:
169 case SymExpr::IntSymExprKind:
172 case SymExpr::SymSymExprKind: {
174 WL->push_back(x->getLHS());
175 WL->push_back(x->getRHS());
179 llvm_unreachable(
"unhandled expansion case");
187 return R->getValueType();
191 ASTContext &Ctx = R->getMemRegionManager().getContext();
200 return R->getValueType();
204 T =
T.getCanonicalType();
209 if (
T->isIntegralOrEnumerationType())
212 if (
T->isRecordType() && !
T->isUnionType())
222 dependencies = std::make_unique<SymbolRefSmallVectorTy>();
229 SymbolDependTy::const_iterator I = SymbolDependencies.find(Primary);
230 if (I == SymbolDependencies.end())
232 return I->second.get();
235void SymbolReaper::markDependentsLive(SymbolMapTy::iterator LI) {
237 if (LI->second == HaveMarkedDependents)
239 LI->second = HaveMarkedDependents;
242 if (
const auto *Deps = SymMgr.getDependentSymbols(LI->first)) {
243 for (
const auto I : *Deps) {
244 if (TheLiving.contains(I))
252 markDependentsLive(TheLiving.try_emplace(Sym, NotProcessed).first);
265 for (
auto SR = dyn_cast<SubRegion>(region); SR;
266 SR = dyn_cast<SubRegion>(SR->getSuperRegion())) {
267 if (
const auto ER = dyn_cast<ElementRegion>(SR)) {
268 SVal Idx = ER->getIndex();
277 MetadataInUse.insert(sym);
286 if (LiveRegionRoots.count(MR))
289 if (
const auto *SR = dyn_cast<SymbolicRegion>(MR))
290 return isLive(SR->getSymbol());
292 if (
const auto *VR = dyn_cast<VarRegion>(MR))
302bool SymbolReaper::isLazilyCopiedRegion(
const MemRegion *MR)
const {
307bool SymbolReaper::isReadableRegion(
const MemRegion *MR) {
308 return isLiveRegion(MR) || isLazilyCopiedRegion(MR);
312 if (
auto LI = TheLiving.find(Sym); LI != TheLiving.end()) {
313 markDependentsLive(LI);
320 case SymExpr::SymbolRegionValueKind:
323 case SymExpr::SymbolConjuredKind:
326 case SymExpr::SymbolDerivedKind:
329 case SymExpr::SymbolExtentKind:
332 case SymExpr::SymbolMetadataKind:
333 KnownLive = MetadataInUse.count(Sym) &&
336 MetadataInUse.erase(Sym);
338 case SymExpr::SymIntExprKind:
341 case SymExpr::IntSymExprKind:
344 case SymExpr::SymSymExprKind:
348 case SymExpr::SymbolCastKind:
351 case SymExpr::UnarySymExprKind:
369 if (SF->isParentOf(ESF))
392 if (VarSF == CurrentSF) {
405 if (!includeStoreBindings)
408 unsigned &cachedQuery =
409 const_cast<SymbolReaper *
>(
this)->includedRegionCache[VR];
412 return cachedQuery == 1;
416 if (
Store store = reapedStore.getStore()) {
418 reapedStore.getStoreManager().includedInBindings(store, VR);
419 cachedQuery = hasRegion ? 1 : 2;
Defines the clang::ASTContext interface.
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.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
QualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
StringRef getOpcodeStr() const
BinaryOperatorKind Opcode
Represents C++ object destructor implicitly generated for automatic object or temporary bound to cons...
Represents a function call that returns a C++ object by value.
Represents C++ constructor call.
Represents C++ object destructor generated from a call to delete.
Represents C++ base or member initializer from constructor's initialization list.
const CXXCtorInitializer * getInitializer() const
Represents the point where the lifetime of an automatic object ends.
Represents the point where a loop ends.
Represents C++ allocator call.
Represents beginning of a scope implicitly generated by the compiler on encountering a CompoundStmt.
Represents end of a scope implicitly generated by the compiler after the last Stmt in a CompoundStmt'...
Represents C++ object destructor implicitly generated at the end of full expression for temporary obj...
This represents one expression.
bool isLive(const CFGBlock *B, const VarDecl *D)
Return true if a variable is live at the end of a specified block.
A (possibly-)qualified type.
It represents a stack frame of the call stack.
bool isParentOf(const StackFrame *SF) const
Stmt - This represents one statement.
static StringRef getOpcodeStr(Opcode Op)
getOpcodeStr - Turn an Opcode enum value into the punctuation char it corresponds to,...
static void dumpToStreamImpl(raw_ostream &os, const SymExpr *Value)
static bool isLocType(QualType T)
MemRegion - The root abstract class for all memory regions.
LLVM_ATTRIBUTE_RETURNS_NONNULL const MemRegion * getBaseRegion() const
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
SymExpr::symbol_range symbols() const
virtual void dumpToStream(raw_ostream &os) const
SymExpr(Kind k, SymbolID Sym)
virtual void dump() const
SymbolID getSymbolID() const
Get a unique identifier for this symbol.
void dumpToStream(raw_ostream &os) const override
const Stmt * getStmt() const
StringRef getKindStr() const override
Get a string representation of the kind of the region.
void dumpToStream(raw_ostream &os) const override
QualType getType() const override
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
QualType getType() const override
LLVM_ATTRIBUTE_RETURNS_NONNULL const TypedValueRegion * getRegion() const
LLVM_ATTRIBUTE_RETURNS_NONNULL const SubRegion * getRegion() const
void dumpToStream(raw_ostream &os) const override
QualType getType() const override
StringRef getKindStr() const override
Get a string representation of the kind of the region.
void addSymbolDependency(const SymbolRef Primary, const SymbolRef Dependent)
Add artificial symbol dependency.
const SymbolRefSmallVectorTy * getDependentSymbols(const SymbolRef Primary)
static bool canSymbolicate(QualType T)
void markElementIndicesLive(const MemRegion *region)
void markInUse(SymbolRef sym)
Marks a symbol as important to a checker.
bool isLiveRegion(const MemRegion *region)
void markLazilyCopied(const MemRegion *region)
void markLive(SymbolRef Sym)
Unconditionally marks a symbol as live.
bool isLive(SymbolRef Sym)
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 dumpToStream(raw_ostream &os) const override
QualType getType() const override
StringRef getKindStr() const override
Get a string representation of the kind of the region.
void dumpToStream(raw_ostream &os) const override
const VarDecl * getDecl() const override=0
const StackFrame * getStackFrame() const
It might return null.
SmallVector< SymbolRef, 2 > SymbolRefSmallVectorTy
const SymExpr * SymbolRef
@ OS
Indicates that the tracking object is a descendant of a referenced-counted OSObject,...
const void * Store
Store - This opaque type encapsulates an immutable mapping from locations to values.
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
@ Dependent
Parse the block as a dependent block, which may be used in some template instantiations but not other...
const FunctionProtoType * T
U cast(CodeGen::Address addr)