24#include "llvm/Support/Compiler.h"
25#include "llvm/Support/ErrorHandling.h"
26#include "llvm/Support/raw_ostream.h"
32void SymExpr::anchor() {}
49 const llvm::APSInt &
Value) {
50 if (
Value.isUnsigned())
54 if (
Value.isUnsigned())
64 os <<
'(' << ToTy <<
") (";
71 bool Binary = isa<BinarySymExpr>(Operand);
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();
128 os <<
", #" << Count <<
'}';
144void SymbolData::anchor() {}
163 assert(!itr.empty() &&
"attempting to iterate on an 'end' iterator");
169 assert(!itr.empty() &&
"attempting to dereference an 'end' iterator");
173void SymExpr::symbol_iterator::expand() {
174 const SymExpr *SE = itr.pop_back_val();
177 case SymExpr::SymbolRegionValueKind:
178 case SymExpr::SymbolConjuredKind:
179 case SymExpr::SymbolDerivedKind:
180 case SymExpr::SymbolExtentKind:
181 case SymExpr::SymbolMetadataKind:
183 case SymExpr::SymbolCastKind:
184 itr.push_back(cast<SymbolCast>(SE)->getOperand());
186 case SymExpr::UnarySymExprKind:
187 itr.push_back(cast<UnarySymExpr>(SE)->getOperand());
189 case SymExpr::SymIntExprKind:
190 itr.push_back(cast<SymIntExpr>(SE)->getLHS());
192 case SymExpr::IntSymExprKind:
193 itr.push_back(cast<IntSymExpr>(SE)->getRHS());
195 case SymExpr::SymSymExprKind: {
196 const auto *x = cast<SymSymExpr>(SE);
197 itr.push_back(x->getLHS());
198 itr.push_back(x->getRHS());
202 llvm_unreachable(
"unhandled expansion case");
210 return R->getValueType();
214 ASTContext &Ctx = R->getMemRegionManager().getContext();
223 return R->getValueType();
227 T =
T.getCanonicalType();
243 auto &dependencies = SymbolDependencies[Primary];
245 dependencies = std::make_unique<SymbolRefSmallVectorTy>();
252 SymbolDependTy::const_iterator I = SymbolDependencies.find(Primary);
253 if (I == SymbolDependencies.end())
255 return I->second.get();
258void SymbolReaper::markDependentsLive(
SymbolRef sym) {
260 SymbolMapTy::iterator LI = TheLiving.find(sym);
261 assert(LI != TheLiving.end() &&
"The primary symbol is not live.");
262 if (LI->second == HaveMarkedDependents)
264 LI->second = HaveMarkedDependents;
267 for (
const auto I : *Deps) {
268 if (TheLiving.contains(I))
276 TheLiving[sym] = NotProcessed;
277 markDependentsLive(sym);
282 markElementIndicesLive(region);
290 for (
auto SR = dyn_cast<SubRegion>(region); SR;
291 SR = dyn_cast<SubRegion>(SR->getSuperRegion())) {
292 if (
const auto ER = dyn_cast<ElementRegion>(SR)) {
293 SVal Idx = ER->getIndex();
301 if (isa<SymbolMetadata>(sym))
302 MetadataInUse.insert(sym);
311 if (LiveRegionRoots.count(MR))
314 if (
const auto *SR = dyn_cast<SymbolicRegion>(MR))
315 return isLive(SR->getSymbol());
317 if (
const auto *VR = dyn_cast<VarRegion>(MR))
318 return isLive(VR,
true);
324 return isa<AllocaRegion, CXXThisRegion, MemSpaceRegion, CodeTextRegion>(MR);
327bool SymbolReaper::isLazilyCopiedRegion(
const MemRegion *MR)
const {
332bool SymbolReaper::isReadableRegion(
const MemRegion *MR) {
333 return isLiveRegion(MR) || isLazilyCopiedRegion(MR);
337 if (TheLiving.count(sym)) {
338 markDependentsLive(sym);
345 case SymExpr::SymbolRegionValueKind:
346 KnownLive = isReadableRegion(cast<SymbolRegionValue>(sym)->
getRegion());
348 case SymExpr::SymbolConjuredKind:
351 case SymExpr::SymbolDerivedKind:
352 KnownLive = isLive(cast<SymbolDerived>(sym)->getParentSymbol());
354 case SymExpr::SymbolExtentKind:
355 KnownLive = isLiveRegion(cast<SymbolExtent>(sym)->
getRegion());
357 case SymExpr::SymbolMetadataKind:
358 KnownLive = MetadataInUse.count(sym) &&
359 isLiveRegion(cast<SymbolMetadata>(sym)->
getRegion());
361 MetadataInUse.erase(sym);
363 case SymExpr::SymIntExprKind:
364 KnownLive = isLive(cast<SymIntExpr>(sym)->getLHS());
366 case SymExpr::IntSymExprKind:
367 KnownLive = isLive(cast<IntSymExpr>(sym)->getRHS());
369 case SymExpr::SymSymExprKind:
370 KnownLive = isLive(cast<SymSymExpr>(sym)->getLHS()) &&
371 isLive(cast<SymSymExpr>(sym)->getRHS());
373 case SymExpr::SymbolCastKind:
374 KnownLive = isLive(cast<SymbolCast>(sym)->getOperand());
376 case SymExpr::UnarySymExprKind:
377 KnownLive = isLive(cast<UnarySymExpr>(sym)->getOperand());
395 if (LCtx->isParentOf(ELCtx))
418 if (VarContext == CurrentContext) {
425 if (isa<CXXInheritedCtorInitExpr>(
Loc))
431 if (!includeStoreBindings)
434 unsigned &cachedQuery =
435 const_cast<SymbolReaper *
>(
this)->includedRegionCache[VR];
438 return cachedQuery == 1;
442 if (
Store store = reapedStore.getStore()) {
444 reapedStore.getStoreManager().includedInBindings(store, VR);
445 cachedQuery = hasRegion ? 1 : 2;
452 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
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.
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...
ASTContext & getASTContext() const LLVM_READONLY
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 Decl * getDecl() 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.
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
bool isRecordType() const
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
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)
A class responsible for cleaning up unused symbols.
void markLive(SymbolRef sym)
Unconditionally marks a symbol as live.
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)
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.
@ 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.
@ Dependent
Parse the block as a dependent block, which may be used in some template instantiations but not other...
const FunctionProtoType * T