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();
125 itr.push_back(cast<SymbolCast>(SE)->getOperand());
128 itr.push_back(cast<SymIntExpr>(SE)->getLHS());
131 itr.push_back(cast<IntSymExpr>(SE)->getRHS());
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);
349 SymbolDependTy::iterator I = SymbolDependencies.find(Primary);
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) {
370 SymbolMapTy::iterator LI = TheLiving.find(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);
397 if (isa<SymbolMetadata>(sym))
398 MetadataInUse.insert(sym);
410 if (RegionRoots.count(MR))
416 return isLive(SR->getSymbol());
418 if (
const VarRegion *VR = dyn_cast<VarRegion>(MR))
419 return isLive(VR,
true);
425 if (isa<AllocaRegion>(MR))
428 if (isa<CXXThisRegion>(MR))
431 if (isa<MemSpaceRegion>(MR))
434 if (isa<CodeTextRegion>(MR))
441 if (TheLiving.count(sym)) {
442 markDependentsLive(sym);
450 KnownLive = isLiveRegion(cast<SymbolRegionValue>(sym)->getRegion());
456 KnownLive = isLive(cast<SymbolDerived>(sym)->getParentSymbol());
459 KnownLive = isLiveRegion(cast<SymbolExtent>(sym)->getRegion());
462 KnownLive = MetadataInUse.count(sym) &&
463 isLiveRegion(cast<SymbolMetadata>(sym)->getRegion());
465 MetadataInUse.erase(sym);
468 KnownLive = isLive(cast<SymIntExpr>(sym)->getLHS());
471 KnownLive = isLive(cast<IntSymExpr>(sym)->getRHS());
474 KnownLive = isLive(cast<SymSymExpr>(sym)->getLHS()) &&
475 isLive(cast<SymSymExpr>(sym)->getRHS());
478 KnownLive = isLive(cast<SymbolCast>(sym)->getOperand());
496 if (LCtx->isParentOf(ELCtx))
518 if (VarContext == CurrentContext) {
526 if (!includeStoreBindings)
529 unsigned &cachedQuery =
530 const_cast<SymbolReaper*
>(
this)->includedRegionCache[VR];
533 return cachedQuery == 1;
537 if (
Store store = reapedStore.getStore()) {
539 reapedStore.getStoreManager().includedInBindings(store, VR);
540 cachedQuery = hasRegion ? 1 : 2;
547 return VarContext->
isParentOf(CurrentContext);
SmallVector< SymbolRef, 2 > SymbolRefSmallVectorTy
TypedValueRegion - An abstract class representing regions having a typed value.
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
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)
Symbolic value. These values used to capture symbolic execution of the program.
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
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)
virtual void dump() const
const VarDecl * getDecl() const
static bool isLocType(QualType T)
bool isLiveRegion(const MemRegion *region)
bool isLive(const CFGBlock *B, const VarDecl *D)
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.
QualType getType() const override
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)
ID
Defines the set of possible language-specific address spaces.
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 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.
QualType getType() const override
Represents a symbolic expression like 3 - 'x'.
void dumpToStream(raw_ostream &os) const override
A class responsible for cleaning up unused symbols.
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
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
BinaryOperator::Opcode getOpcode() const
static void Profile(llvm::FoldingSetNodeID &profile, const SubRegion *R)
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
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.