19 #include "llvm/Support/raw_ostream.h"
21 using namespace clang;
24 void SymExpr::anchor() { }
35 <<
getRHS().getZExtValue();
41 os <<
getLHS().getZExtValue();
85 void SymbolData::anchor() { }
104 assert(!itr.empty() &&
"attempting to iterate on an 'end' iterator");
110 assert(!itr.empty() &&
"attempting to dereference an 'end' iterator");
114 void SymExpr::symbol_iterator::expand() {
115 const SymExpr *SE = itr.pop_back_val();
118 case SymExpr::SymbolRegionValueKind:
119 case SymExpr::SymbolConjuredKind:
120 case SymExpr::SymbolDerivedKind:
121 case SymExpr::SymbolExtentKind:
122 case SymExpr::SymbolMetadataKind:
124 case SymExpr::SymbolCastKind:
125 itr.push_back(cast<SymbolCast>(SE)->getOperand());
127 case SymExpr::SymIntExprKind:
128 itr.push_back(cast<SymIntExpr>(SE)->getLHS());
130 case SymExpr::IntSymExprKind:
131 itr.push_back(cast<IntSymExpr>(SE)->getRHS());
133 case SymExpr::SymSymExprKind: {
135 itr.push_back(x->
getLHS());
136 itr.push_back(x->
getRHS());
140 llvm_unreachable(
"unhandled expansion case");
152 llvm::FoldingSetNodeID profile;
155 SymExpr *SD = DataSet.FindNodeOrInsertPos(profile, InsertPos);
159 DataSet.InsertNode(SD, InsertPos);
163 return cast<SymbolRegionValue>(SD);
170 const void *SymbolTag) {
171 llvm::FoldingSetNodeID profile;
174 SymExpr *SD = DataSet.FindNodeOrInsertPos(profile, InsertPos);
177 new (SD)
SymbolConjured(SymbolCounter, E, LCtx, T, Count, SymbolTag);
178 DataSet.InsertNode(SD, InsertPos);
182 return cast<SymbolConjured>(SD);
189 llvm::FoldingSetNodeID profile;
192 SymExpr *SD = DataSet.FindNodeOrInsertPos(profile, InsertPos);
196 DataSet.InsertNode(SD, InsertPos);
200 return cast<SymbolDerived>(SD);
205 llvm::FoldingSetNodeID profile;
208 SymExpr *SD = DataSet.FindNodeOrInsertPos(profile, InsertPos);
212 DataSet.InsertNode(SD, InsertPos);
216 return cast<SymbolExtent>(SD);
221 unsigned Count,
const void *SymbolTag) {
223 llvm::FoldingSetNodeID profile;
226 SymExpr *SD = DataSet.FindNodeOrInsertPos(profile, InsertPos);
229 new (SD)
SymbolMetadata(SymbolCounter, R, S, T, Count, SymbolTag);
230 DataSet.InsertNode(SD, InsertPos);
234 return cast<SymbolMetadata>(SD);
240 llvm::FoldingSetNodeID
ID;
243 SymExpr *data = DataSet.FindNodeOrInsertPos(ID, InsertPos);
247 DataSet.InsertNode(data, InsertPos);
250 return cast<SymbolCast>(data);
255 const llvm::APSInt&
v,
257 llvm::FoldingSetNodeID
ID;
260 SymExpr *data = DataSet.FindNodeOrInsertPos(ID, InsertPos);
265 DataSet.InsertNode(data, InsertPos);
268 return cast<SymIntExpr>(data);
275 llvm::FoldingSetNodeID
ID;
278 SymExpr *data = DataSet.FindNodeOrInsertPos(ID, InsertPos);
283 DataSet.InsertNode(data, InsertPos);
286 return cast<IntSymExpr>(data);
293 llvm::FoldingSetNodeID
ID;
296 SymExpr *data = DataSet.FindNodeOrInsertPos(ID, InsertPos);
301 DataSet.InsertNode(data, InsertPos);
304 return cast<SymSymExpr>(data);
312 return R->getValueType();
316 ASTContext &Ctx = R->getMemRegionManager()->getContext();
325 return R->getValueType();
329 llvm::DeleteContainerSeconds(SymbolDependencies);
351 if (I == SymbolDependencies.end()) {
353 SymbolDependencies[Primary] = dependencies;
355 dependencies = I->second;
357 dependencies->push_back(Dependent);
362 SymbolDependTy::const_iterator
I = SymbolDependencies.find(Primary);
363 if (I == SymbolDependencies.end())
368 void SymbolReaper::markDependentsLive(
SymbolRef sym) {
371 assert(LI != TheLiving.end() &&
"The primary symbol is not live.");
372 if (LI->second == HaveMarkedDependents)
374 LI->second = HaveMarkedDependents;
377 for (SymbolRefSmallVectorTy::const_iterator
I = Deps->begin(),
378 E = Deps->end();
I !=
E; ++
I) {
379 if (TheLiving.find(*
I) != TheLiving.end())
387 TheLiving[sym] = NotProcessed;
389 markDependentsLive(sym);
393 RegionRoots.insert(region);
394 markElementIndicesLive(region);
398 for (
auto SR = dyn_cast<SubRegion>(region); SR;
399 SR = dyn_cast<
SubRegion>(SR->getSuperRegion())) {
400 if (
auto ER = dyn_cast<ElementRegion>(SR)) {
401 SVal Idx = ER->getIndex();
409 if (isa<SymbolMetadata>(sym))
410 MetadataInUse.insert(sym);
422 if (RegionRoots.count(MR))
428 return isLive(SR->getSymbol());
430 if (
const VarRegion *VR = dyn_cast<VarRegion>(MR))
431 return isLive(VR,
true);
437 if (isa<AllocaRegion>(MR))
440 if (isa<CXXThisRegion>(MR))
443 if (isa<MemSpaceRegion>(MR))
446 if (isa<CodeTextRegion>(MR))
453 if (TheLiving.count(sym)) {
454 markDependentsLive(sym);
461 case SymExpr::SymbolRegionValueKind:
462 KnownLive = isLiveRegion(cast<SymbolRegionValue>(sym)->getRegion());
464 case SymExpr::SymbolConjuredKind:
467 case SymExpr::SymbolDerivedKind:
468 KnownLive = isLive(cast<SymbolDerived>(sym)->getParentSymbol());
470 case SymExpr::SymbolExtentKind:
471 KnownLive = isLiveRegion(cast<SymbolExtent>(sym)->getRegion());
473 case SymExpr::SymbolMetadataKind:
474 KnownLive = MetadataInUse.count(sym) &&
475 isLiveRegion(cast<SymbolMetadata>(sym)->getRegion());
477 MetadataInUse.erase(sym);
479 case SymExpr::SymIntExprKind:
480 KnownLive = isLive(cast<SymIntExpr>(sym)->getLHS());
482 case SymExpr::IntSymExprKind:
483 KnownLive = isLive(cast<IntSymExpr>(sym)->getRHS());
485 case SymExpr::SymSymExprKind:
486 KnownLive = isLive(cast<SymSymExpr>(sym)->getLHS()) &&
487 isLive(cast<SymSymExpr>(sym)->getRHS());
489 case SymExpr::SymbolCastKind:
490 KnownLive = isLive(cast<SymbolCast>(sym)->getOperand());
508 if (LCtx->isParentOf(ELCtx))
530 if (VarContext == CurrentContext) {
538 if (!includeStoreBindings)
541 unsigned &cachedQuery =
542 const_cast<SymbolReaper*
>(
this)->includedRegionCache[VR];
545 return cachedQuery == 1;
549 if (
Store store = reapedStore.getStore()) {
551 reapedStore.getStoreManager().includedInBindings(store, VR);
552 cachedQuery = hasRegion ? 1 : 2;
559 return VarContext->
isParentOf(CurrentContext);
SmallVector< SymbolRef, 2 > SymbolRefSmallVectorTy
virtual void dump() const
TypedValueRegion - An abstract class representing regions having a typed value.
A (possibly-)qualified type.
MemRegion - The root abstract class for all memory regions.
bool operator==(const symbol_iterator &X) const
void markLive(SymbolRef sym)
Unconditionally marks a symbol as live.
const llvm::APSInt & getRHS() const
const SymExpr * getLHS() const
bool maybeDead(SymbolRef sym)
If a symbol is known to be live, marks the symbol as live.
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
const IntSymExpr * getIntSymExpr(const llvm::APSInt &lhs, BinaryOperator::Opcode op, const SymExpr *rhs, QualType t)
const StackFrameContext * getStackFrame() const
static void Profile(llvm::FoldingSetNodeID &profile, const TypedValueRegion *R)
bool isRecordType() const
std::string getAsString() const
const void * Store
Store - This opaque type encapsulates an immutable mapping from locations to values.
symbol_iterator & operator++()
const SymExpr * getRHS() const
void dumpToStream(raw_ostream &os) const override
void dumpToStream(raw_ostream &os) const override
SymbolRef getParentSymbol() const
const MemRegion * getBaseRegion() const
const SymbolRefSmallVectorTy * getDependentSymbols(const SymbolRef Primary)
const SymbolDerived * getDerivedSymbol(SymbolRef parentSymbol, const TypedValueRegion *R)
void markInUse(SymbolRef sym)
Marks a symbol as important to a checker.
SymbolID getSymbolID() const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
static void Profile(llvm::FoldingSetNodeID &profile, SymbolRef parent, const TypedValueRegion *r)
unsigned computeComplexity() const
void markElementIndicesLive(const MemRegion *region)
static bool canSymbolicate(QualType T)
bool operator!=(const symbol_iterator &X) const
void addSymbolDependency(const SymbolRef Primary, const SymbolRef Dependent)
Add artificial symbol dependency.
const SymExpr * getLHS() const
static void Profile(llvm::FoldingSetNodeID &ID, const SymExpr *lhs, BinaryOperator::Opcode op, const llvm::APSInt &rhs, QualType t)
const VarDecl * getDecl() const
static bool isLocType(QualType T)
bool isLiveRegion(const MemRegion *region)
bool isLive(const CFGBlock *B, const VarDecl *D)
Return true if a variable is live at the end of a specified block.
const SymIntExpr * getSymIntExpr(const SymExpr *lhs, BinaryOperator::Opcode op, const llvm::APSInt &rhs, QualType t)
bool isParentOf(const LocationContext *LC) const
const SubRegion * getRegion() const
Represents a symbolic expression like 'x' + 3.
A symbol representing the value of a MemRegion whose parent region has symbolic value.
SymExpr::symbol_iterator symbol_begin() const
QualType getType() const override
detail::InMemoryDirectory::const_iterator I
static void Profile(llvm::FoldingSetNodeID &ID, const llvm::APSInt &lhs, BinaryOperator::Opcode op, const SymExpr *rhs, QualType t)
static void Profile(llvm::FoldingSetNodeID &profile, const Stmt *S, QualType T, unsigned Count, const LocationContext *LCtx, const void *SymbolTag)
SymbolicRegion - A special, "non-concrete" region.
Represents a cast expression.
const TypedValueRegion * getRegion() const
const SymExpr * getRHS() const
const SymbolCast * getCastSymbol(const SymExpr *Operand, QualType From, QualType To)
const SymSymExpr * getSymSymExpr(const SymExpr *lhs, BinaryOperator::Opcode op, const SymExpr *rhs, QualType t)
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
QualType getType() const override
const TemplateArgument * iterator
const StackFrameContext * getCurrentStackFrame() const
const SymbolRegionValue * getRegionValueSymbol(const TypedValueRegion *R)
Make a unique symbol for MemRegion R according to its kind.
const SymbolMetadata * getMetadataSymbol(const MemRegion *R, const Stmt *S, QualType T, unsigned VisitCount, const void *SymbolTag=nullptr)
Creates a metadata symbol associated with a specific region.
SymExpr::symbol_iterator symbol_end() const
QualType getType() const override
SVal - This represents a symbolic expression, which can be either an L-value or an R-value...
Represents a symbolic expression like 3 - 'x'.
void dumpToStream(raw_ostream &os) const override
A class responsible for cleaning up unused symbols.
A symbol representing the result of an expression in the case when we do not know anything about what...
void dumpToStream(raw_ostream &os) const override
A symbol representing the value stored at a MemRegion.
StringRef getOpcodeStr() const
static void Profile(llvm::FoldingSetNodeID &ID, const SymExpr *In, QualType From, QualType To)
const llvm::APSInt & getLHS() const
static symbol_iterator symbol_end()
QualType getType() const override
detail::InMemoryDirectory::const_iterator E
const SymbolConjured * conjureSymbol(const Stmt *E, const LocationContext *LCtx, QualType T, unsigned VisitCount, const void *SymbolTag=nullptr)
virtual void dumpToStream(raw_ostream &os) const
QualType getCanonicalType() const
SubRegion - A region that subsets another larger region.
BinaryOperator::Opcode getOpcode() const
static void Profile(llvm::FoldingSetNodeID &profile, const SubRegion *R)
X
Add a minimal nested name specifier fixit hint to allow lookup of a tag name from an outer enclosing ...
const SymbolExtent * getExtentSymbol(const SubRegion *R)
void dumpToStream(raw_ostream &os) const override
symbol_iterator symbol_begin() const
void dumpToStream(raw_ostream &os) const override
const SymExpr * operator*()
void dumpToStream(raw_ostream &os) const override
SymbolExtent - Represents the extent (size in bytes) of a bounded region.
void dumpToStream(raw_ostream &os) const override
Represents a symbolic expression like 'x' + 'y'.
bool isLive(SymbolRef sym)
static void Profile(llvm::FoldingSetNodeID &ID, const SymExpr *lhs, BinaryOperator::Opcode op, const SymExpr *rhs, QualType t)
Iterator over symbols that the current symbol depends on.