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(LCtx->getDecl()->getASTContext());
130 os <<
", #" << Count <<
'}';
146void SymbolData::anchor() {}
165 assert(!itr.empty() &&
"attempting to iterate on an 'end' iterator");
171 assert(!itr.empty() &&
"attempting to dereference an 'end' iterator");
175void SymExpr::symbol_iterator::expand() {
176 const SymExpr *SE = itr.pop_back_val();
179 case SymExpr::SymbolRegionValueKind:
180 case SymExpr::SymbolConjuredKind:
181 case SymExpr::SymbolDerivedKind:
182 case SymExpr::SymbolExtentKind:
183 case SymExpr::SymbolMetadataKind:
185 case SymExpr::SymbolCastKind:
188 case SymExpr::UnarySymExprKind:
191 case SymExpr::SymIntExprKind:
194 case SymExpr::IntSymExprKind:
197 case SymExpr::SymSymExprKind: {
199 itr.push_back(x->getLHS());
200 itr.push_back(x->getRHS());
204 llvm_unreachable(
"unhandled expansion case");
212 return R->getValueType();
216 ASTContext &Ctx = R->getMemRegionManager().getContext();
225 return R->getValueType();
229 T = T.getCanonicalType();
234 if (T->isIntegralOrEnumerationType())
237 if (T->isRecordType() && !T->isUnionType())
247 dependencies = std::make_unique<SymbolRefSmallVectorTy>();
254 SymbolDependTy::const_iterator I = SymbolDependencies.find(Primary);
255 if (I == SymbolDependencies.end())
257 return I->second.get();
260void SymbolReaper::markDependentsLive(
SymbolRef sym) {
262 SymbolMapTy::iterator LI = TheLiving.find(sym);
263 assert(LI != TheLiving.end() &&
"The primary symbol is not live.");
264 if (LI->second == HaveMarkedDependents)
266 LI->second = HaveMarkedDependents;
269 for (
const auto I : *Deps) {
270 if (TheLiving.contains(I))
278 TheLiving[sym] = NotProcessed;
279 markDependentsLive(sym);
292 for (
auto SR = dyn_cast<SubRegion>(region); SR;
293 SR = dyn_cast<SubRegion>(SR->getSuperRegion())) {
294 if (
const auto ER = dyn_cast<ElementRegion>(SR)) {
295 SVal Idx = ER->getIndex();
304 MetadataInUse.insert(sym);
313 if (LiveRegionRoots.count(MR))
316 if (
const auto *SR = dyn_cast<SymbolicRegion>(MR))
317 return isLive(SR->getSymbol());
319 if (
const auto *VR = dyn_cast<VarRegion>(MR))
329bool SymbolReaper::isLazilyCopiedRegion(
const MemRegion *MR)
const {
334bool SymbolReaper::isReadableRegion(
const MemRegion *MR) {
335 return isLiveRegion(MR) || isLazilyCopiedRegion(MR);
339 if (TheLiving.count(sym)) {
340 markDependentsLive(sym);
347 case SymExpr::SymbolRegionValueKind:
350 case SymExpr::SymbolConjuredKind:
353 case SymExpr::SymbolDerivedKind:
356 case SymExpr::SymbolExtentKind:
359 case SymExpr::SymbolMetadataKind:
360 KnownLive = MetadataInUse.count(sym) &&
363 MetadataInUse.erase(sym);
365 case SymExpr::SymIntExprKind:
368 case SymExpr::IntSymExprKind:
371 case SymExpr::SymSymExprKind:
375 case SymExpr::SymbolCastKind:
378 case SymExpr::UnarySymExprKind:
397 if (LCtx->isParentOf(ELCtx))
420 if (VarContext == CurrentContext) {
433 if (!includeStoreBindings)
436 unsigned &cachedQuery =
437 const_cast<SymbolReaper *
>(
this)->includedRegionCache[VR];
440 return cachedQuery == 1;
444 if (
Store store = reapedStore.getStore()) {
446 reapedStore.getStoreManager().includedInBindings(store, VR);
447 cachedQuery = hasRegion ? 1 : 2;
454 return VarContext->
isParentOf(CurrentContext);
Defines the clang::ASTContext interface.
This file defines AnalysisDeclContext, a class that manages the analysis context data for context sen...
static const MemRegion * getRegion(const CallEvent &Call, const MutexDescriptor &Descriptor, bool IsLock)
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.
It wraps the AnalysisDeclContext to represent both the call stack with the help of StackFrameContext ...
bool isParentOf(const LocationContext *LC) const
const StackFrameContext * getStackFrame() const
A (possibly-)qualified type.
It represents a stack frame of the call stack (based on CallEvent).
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.
llvm::iterator_range< SymExpr::symbol_iterator > symbols() const
Iterator over symbols that the current symbol depends on.
symbol_iterator()=default
bool operator!=(const symbol_iterator &X) const
symbol_iterator & operator++()
bool operator==(const symbol_iterator &X) const
const SymExpr * operator*()
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 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...
void markInUse(SymbolRef sym)
Marks a symbol as important to a checker.
bool isLiveRegion(const MemRegion *region)
void markLazilyCopied(const MemRegion *region)
bool isLive(SymbolRef sym)
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 StackFrameContext * 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.
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
@ Dependent
Parse the block as a dependent block, which may be used in some template instantiations but not other...
U cast(CodeGen::Address addr)