aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/SymbolManager.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-01-22 18:23:34 +0000
committerTed Kremenek <kremenek@apple.com>2009-01-22 18:23:34 +0000
commit9ab6b9cfb76ee56a61829e2bdb08e5cdc288726e (patch)
treece8772d0a73edbd6ce7aa138ee9ccc7b6d1bd738 /lib/Analysis/SymbolManager.cpp
parent07c487e5f73c3e6ea47a03b674a4a0f753adf90f (diff)
Static analyzer: Remove a bunch of outdated SymbolData objects and
their associated APIs. We no longer need separate SymbolData objects for fields, variables, etc. Instead, we now associated symbols with the "rvalue" of a MemRegion (i.e., the value stored at that region). Now we only have two kinds of SymbolData objects: SymbolRegionRValue and SymbolConjured. This cleanup also makes the distinction between a SymbolicRegion and a symbolic value that is a location much clearer. A SymbolicRegion represents a chunk of symbolic memory, while a symbolic location is just a "pointer" with different possible values. Without any specific knowledge, a symbolic location resolves (i.e., via a dereference) to a SymbolicRegion. In the future, when we do better alias reasoning, a symbolic location can become an alias for another location, thus merging the constraints on the referred SymbolicRegion with the other region. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62769 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/SymbolManager.cpp')
-rw-r--r--lib/Analysis/SymbolManager.cpp117
1 files changed, 18 insertions, 99 deletions
diff --git a/lib/Analysis/SymbolManager.cpp b/lib/Analysis/SymbolManager.cpp
index d0099e15fa..54ba7b1d93 100644
--- a/lib/Analysis/SymbolManager.cpp
+++ b/lib/Analysis/SymbolManager.cpp
@@ -22,99 +22,23 @@ void SymbolRef::print(llvm::raw_ostream& os) const {
os << getNumber();
}
-SymbolRef SymbolManager::getSymbol(const MemRegion* R) {
- switch (R->getKind()) {
- default:
- assert(0 && "unprocessed region");
- case MemRegion::VarRegionKind:
- return getSymbol(cast<VarRegion>(R)->getDecl());
-
- case MemRegion::ElementRegionKind: {
- const ElementRegion* ER = cast<ElementRegion>(R);
- const llvm::APSInt& Idx =
- cast<nonloc::ConcreteInt>(ER->getIndex()).getValue();
- return getElementSymbol(ER->getSuperRegion(), &Idx);
- }
-
- case MemRegion::FieldRegionKind: {
- const FieldRegion* FR = cast<FieldRegion>(R);
- return getFieldSymbol(FR->getSuperRegion(), FR->getDecl());
- }
- }
-}
-
-SymbolRef SymbolManager::getSymbol(const VarDecl* D) {
-
- assert (isa<ParmVarDecl>(D) || isa<ImplicitParamDecl>(D) ||
- D->hasGlobalStorage());
-
+SymbolRef SymbolManager::getRegionRValueSymbol(const MemRegion* R) {
llvm::FoldingSetNodeID profile;
-
- const ParmVarDecl* PD = dyn_cast<ParmVarDecl>(D);
-
- if (PD)
- SymbolDataParmVar::Profile(profile, PD);
- else
- SymbolDataGlobalVar::Profile(profile, D);
-
- void* InsertPos;
-
- SymbolData* SD = DataSet.FindNodeOrInsertPos(profile, InsertPos);
- if (SD)
- return SD->getSymbol();
-
- if (PD) {
- SD = (SymbolData*) BPAlloc.Allocate<SymbolDataParmVar>();
- new (SD) SymbolDataParmVar(SymbolCounter, PD);
- }
- else {
- SD = (SymbolData*) BPAlloc.Allocate<SymbolDataGlobalVar>();
- new (SD) SymbolDataGlobalVar(SymbolCounter, D);
- }
+ SymbolRegionRValue::Profile(profile, R);
+ void* InsertPos;
+ SymbolData* SD = DataSet.FindNodeOrInsertPos(profile, InsertPos);
+ if (SD) return SD->getSymbol();
+ SD = (SymbolData*) BPAlloc.Allocate<SymbolRegionRValue>();
+ new (SD) SymbolRegionRValue(SymbolCounter, R);
DataSet.InsertNode(SD, InsertPos);
-
- DataMap[SymbolCounter] = SD;
- return SymbolCounter++;
-}
-
-SymbolRef SymbolManager::getElementSymbol(const MemRegion* R,
- const llvm::APSInt* Idx){
- llvm::FoldingSetNodeID ID;
- SymbolDataElement::Profile(ID, R, Idx);
- void* InsertPos;
- SymbolData* SD = DataSet.FindNodeOrInsertPos(ID, InsertPos);
-
- if (SD)
- return SD->getSymbol();
-
- SD = (SymbolData*) BPAlloc.Allocate<SymbolDataElement>();
- new (SD) SymbolDataElement(SymbolCounter, R, Idx);
-
- DataSet.InsertNode(SD, InsertPos);
- DataMap[SymbolCounter] = SD;
+ DataMap[SymbolCounter] = SD;
return SymbolCounter++;
-}
-
-SymbolRef SymbolManager::getFieldSymbol(const MemRegion* R, const FieldDecl* D) {
- llvm::FoldingSetNodeID ID;
- SymbolDataField::Profile(ID, R, D);
- void* InsertPos;
- SymbolData* SD = DataSet.FindNodeOrInsertPos(ID, InsertPos);
- if (SD)
- return SD->getSymbol();
-
- SD = (SymbolData*) BPAlloc.Allocate<SymbolDataField>();
- new (SD) SymbolDataField(SymbolCounter, R, D);
-
- DataSet.InsertNode(SD, InsertPos);
- DataMap[SymbolCounter] = SD;
- return SymbolCounter++;
}
-SymbolRef SymbolManager::getConjuredSymbol(Stmt* E, QualType T, unsigned Count) {
+SymbolRef SymbolManager::getConjuredSymbol(Stmt* E, QualType T, unsigned Count){
llvm::FoldingSetNodeID profile;
SymbolConjured::Profile(profile, E, T, Count);
@@ -141,20 +65,15 @@ const SymbolData& SymbolManager::getSymbolData(SymbolRef Sym) const {
}
-QualType SymbolData::getType(const SymbolManager& SymMgr) const {
- switch (getKind()) {
- default:
- assert (false && "getType() not implemented for this symbol.");
-
- case ParmKind:
- return cast<SymbolDataParmVar>(this)->getDecl()->getType();
-
- case GlobalKind:
- return cast<SymbolDataGlobalVar>(this)->getDecl()->getType();
+QualType SymbolConjured::getType(ASTContext&) const {
+ return T;
+}
- case ConjuredKind:
- return cast<SymbolConjured>(this)->getType();
- }
+QualType SymbolRegionRValue::getType(ASTContext& C) const {
+ if (const TypedRegion* TR = dyn_cast<TypedRegion>(R))
+ return TR->getRValueType(C);
+
+ return QualType();
}
SymbolManager::~SymbolManager() {}
@@ -172,7 +91,7 @@ bool SymbolReaper::maybeDead(SymbolRef sym) {
return true;
}
-bool SymbolReaper::isLive(SymbolRef sym) {
+bool SymbolReaper::isLive(SymbolRef sym) {
return TheLiving.contains(sym);
}