[cfe-commits] r62769 - in /cfe/trunk: include/clang/Analysis/PathSensitive/GRState.h include/clang/Analysis/PathSensitive/SVals.h include/clang/Analysis/PathSensitive/SymbolManager.h lib/Analysis/BasicConstraintManager.cpp lib/Analysis/BasicStore.cpp lib/Analysis/RegionStore.cpp lib/Analysis/SVals.cpp lib/Analysis/SymbolManager.cpp
Ted Kremenek
kremenek at apple.com
Thu Jan 22 10:23:35 PST 2009
Author: kremenek
Date: Thu Jan 22 12:23:34 2009
New Revision: 62769
URL: http://llvm.org/viewvc/llvm-project?rev=62769&view=rev
Log:
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.
Modified:
cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h
cfe/trunk/include/clang/Analysis/PathSensitive/SVals.h
cfe/trunk/include/clang/Analysis/PathSensitive/SymbolManager.h
cfe/trunk/lib/Analysis/BasicConstraintManager.cpp
cfe/trunk/lib/Analysis/BasicStore.cpp
cfe/trunk/lib/Analysis/RegionStore.cpp
cfe/trunk/lib/Analysis/SVals.cpp
cfe/trunk/lib/Analysis/SymbolManager.cpp
Modified: cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h?rev=62769&r1=62768&r2=62769&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h Thu Jan 22 12:23:34 2009
@@ -310,7 +310,7 @@
ISetFactory(alloc),
GDMFactory(alloc),
BasicVals(Ctx, alloc),
- SymMgr(alloc),
+ SymMgr(Ctx, alloc),
Alloc(alloc),
cfg(c),
codedecl(cd),
Modified: cfe/trunk/include/clang/Analysis/PathSensitive/SVals.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/SVals.h?rev=62769&r1=62768&r2=62769&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/SVals.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/SVals.h Thu Jan 22 12:23:34 2009
@@ -72,17 +72,9 @@
return !(*this == R);
}
- /// MakeSymbolValue - make a unique symbol value for the region R according to
- /// its kind. R should be a scalar region. The symbol value T has the same
- /// type as R's rvalue type.
- static SVal MakeSymbolValue(SymbolManager& SymMgr, const MemRegion* R,
- QualType T);
-
- static SVal GetSymbolValue(SymbolManager& SymMgr, VarDecl *D);
- static SVal getSymbolValue(SymbolManager& SymMgr, const MemRegion* R,
- const llvm::APSInt* Idx, QualType T);
- static SVal getSymbolValue(SymbolManager& SymMgr, const MemRegion* R,
- const FieldDecl* FD, QualType T);
+ /// GetRValueSymbolVal - make a unique symbol for value of R.
+ static SVal GetRValueSymbolVal(SymbolManager& SymMgr, const MemRegion* R);
+
inline bool isUnknown() const {
return getRawKind() == UnknownKind;
Modified: cfe/trunk/include/clang/Analysis/PathSensitive/SymbolManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/SymbolManager.h?rev=62769&r1=62768&r2=62769&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/SymbolManager.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/SymbolManager.h Thu Jan 22 12:23:34 2009
@@ -32,6 +32,7 @@
class MemRegion;
class SymbolManager;
+class ASTContext;
class SymbolRef {
unsigned Data;
@@ -80,8 +81,7 @@
class SymbolData : public llvm::FoldingSetNode {
public:
- enum Kind { UndefKind, ParmKind, GlobalKind, ElementKind, FieldKind,
- ConjuredKind };
+ enum Kind { RegionRValue, ConjuredKind };
private:
Kind K;
@@ -97,105 +97,36 @@
SymbolRef getSymbol() const { return Sym; }
- QualType getType(const SymbolManager& SymMgr) const;
+ virtual QualType getType(ASTContext&) const = 0;
virtual void Profile(llvm::FoldingSetNodeID& profile) = 0;
// Implement isa<T> support.
static inline bool classof(const SymbolData*) { return true; }
};
-
-class SymbolDataParmVar : public SymbolData {
- const ParmVarDecl *VD;
-
-public:
- SymbolDataParmVar(SymbolRef MySym, const ParmVarDecl* vd)
- : SymbolData(ParmKind, MySym), VD(vd) {}
-
- const ParmVarDecl* getDecl() const { return VD; }
-
- static void Profile(llvm::FoldingSetNodeID& profile, const ParmVarDecl* VD) {
- profile.AddInteger((unsigned) ParmKind);
- profile.AddPointer(VD);
- }
- virtual void Profile(llvm::FoldingSetNodeID& profile) {
- Profile(profile, VD);
- }
-
- // Implement isa<T> support.
- static inline bool classof(const SymbolData* D) {
- return D->getKind() == ParmKind;
- }
-};
-
-class SymbolDataGlobalVar : public SymbolData {
- const VarDecl *VD;
-
+class SymbolRegionRValue : public SymbolData {
+ const MemRegion *R;
public:
- SymbolDataGlobalVar(SymbolRef MySym, const VarDecl* vd) :
- SymbolData(GlobalKind, MySym), VD(vd) {}
-
- const VarDecl* getDecl() const { return VD; }
+ SymbolRegionRValue(SymbolRef MySym, const MemRegion *r)
+ : SymbolData(RegionRValue, MySym), R(r) {}
- static void Profile(llvm::FoldingSetNodeID& profile, const VarDecl* VD) {
- profile.AddInteger((unsigned) GlobalKind);
- profile.AddPointer(VD);
+ const MemRegion* getRegion() const { return R; }
+
+ static void Profile(llvm::FoldingSetNodeID& profile, const MemRegion* R) {
+ profile.AddInteger((unsigned) RegionRValue);
+ profile.AddPointer(R);
}
virtual void Profile(llvm::FoldingSetNodeID& profile) {
- Profile(profile, VD);
+ Profile(profile, R);
}
+ QualType getType(ASTContext&) const;
+
// Implement isa<T> support.
static inline bool classof(const SymbolData* D) {
- return D->getKind() == GlobalKind;
- }
-};
-
-class SymbolDataElement : public SymbolData {
- const MemRegion* R;
- const llvm::APSInt* Idx;
-
-public:
- SymbolDataElement(SymbolRef MySym, const MemRegion* r, const llvm::APSInt* idx)
- : SymbolData(ElementKind, MySym), R(r), Idx(idx) {}
-
- static void Profile(llvm::FoldingSetNodeID& profile, const MemRegion* R,
- const llvm::APSInt* Idx) {
- profile.AddPointer(R);
- profile.AddPointer(Idx);
- }
-
- void Profile(llvm::FoldingSetNodeID& profile) {
- Profile(profile, R, Idx);
- }
-
- static bool classof(const SymbolData* D) {
- return D->getKind() == ElementKind;
- }
-};
-
-class SymbolDataField : public SymbolData {
- const MemRegion* R;
- const FieldDecl* D;
-
-public:
- SymbolDataField(SymbolRef MySym, const MemRegion* r, const FieldDecl* d)
- : SymbolData(FieldKind, MySym), R(r), D(d) {}
-
- static void Profile(llvm::FoldingSetNodeID& profile, const MemRegion* R,
- const FieldDecl* D) {
- profile.AddPointer(R);
- profile.AddPointer(D);
- }
-
- void Profile(llvm::FoldingSetNodeID& profile) {
- Profile(profile, R, D);
- }
-
- static bool classof(const SymbolData* D) {
- return D->getKind() == FieldKind;
+ return D->getKind() == RegionRValue;
}
};
@@ -210,7 +141,7 @@
Stmt* getStmt() const { return S; }
unsigned getCount() const { return Count; }
- QualType getType() const { return T; }
+ QualType getType(ASTContext&) const;
static void Profile(llvm::FoldingSetNodeID& profile,
Stmt* S, QualType T, unsigned Count) {
@@ -271,18 +202,16 @@
unsigned SymbolCounter;
llvm::BumpPtrAllocator& BPAlloc;
+ ASTContext& Ctx;
public:
- SymbolManager(llvm::BumpPtrAllocator& bpalloc)
- : SymbolCounter(0), BPAlloc(bpalloc) {}
+ SymbolManager(ASTContext& ctx, llvm::BumpPtrAllocator& bpalloc)
+ : SymbolCounter(0), BPAlloc(bpalloc), Ctx(ctx) {}
~SymbolManager();
/// Make a unique symbol for MemRegion R according to its kind.
- SymbolRef getSymbol(const MemRegion* R);
- SymbolRef getSymbol(const VarDecl* D);
- SymbolRef getElementSymbol(const MemRegion* R, const llvm::APSInt* Idx);
- SymbolRef getFieldSymbol(const MemRegion* R, const FieldDecl* D);
+ SymbolRef getRegionRValueSymbol(const MemRegion* R);
SymbolRef getConjuredSymbol(Stmt* E, QualType T, unsigned VisitCount);
SymbolRef getConjuredSymbol(Expr* E, unsigned VisitCount) {
return getConjuredSymbol(E, E->getType(), VisitCount);
@@ -291,8 +220,10 @@
const SymbolData& getSymbolData(SymbolRef ID) const;
QualType getType(SymbolRef ID) const {
- return getSymbolData(ID).getType(*this);
+ return getSymbolData(ID).getType(Ctx);
}
+
+ ASTContext& getContext() { return Ctx; }
};
class SymbolReaper {
Modified: cfe/trunk/lib/Analysis/BasicConstraintManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BasicConstraintManager.cpp?rev=62769&r1=62768&r2=62769&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/BasicConstraintManager.cpp (original)
+++ cfe/trunk/lib/Analysis/BasicConstraintManager.cpp Thu Jan 22 12:23:34 2009
@@ -204,13 +204,12 @@
case nonloc::SymbolValKind: {
nonloc::SymbolVal& SV = cast<nonloc::SymbolVal>(Cond);
SymbolRef sym = SV.getSymbol();
-
+ QualType T = SymMgr.getType(sym);
+
if (Assumption)
- return AssumeSymNE(St, sym, BasicVals.getValue(0, SymMgr.getType(sym)),
- isFeasible);
+ return AssumeSymNE(St, sym, BasicVals.getValue(0, T), isFeasible);
else
- return AssumeSymEQ(St, sym, BasicVals.getValue(0, SymMgr.getType(sym)),
- isFeasible);
+ return AssumeSymEQ(St, sym, BasicVals.getValue(0, T), isFeasible);
}
case nonloc::SymIntConstraintValKind:
Modified: cfe/trunk/lib/Analysis/BasicStore.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BasicStore.cpp?rev=62769&r1=62768&r2=62769&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/BasicStore.cpp (original)
+++ cfe/trunk/lib/Analysis/BasicStore.cpp Thu Jan 22 12:23:34 2009
@@ -454,12 +454,13 @@
if (Loc::IsLocType(T) || T->isIntegerType()) {
// Initialize globals and parameters to symbolic values.
// Initialize local variables to undefined.
+ const MemRegion *R = StateMgr.getRegion(VD);
SVal X = (VD->hasGlobalStorage() || isa<ParmVarDecl>(VD) ||
isa<ImplicitParamDecl>(VD))
- ? SVal::GetSymbolValue(StateMgr.getSymbolManager(), VD)
- : UndefinedVal();
+ ? SVal::GetRValueSymbolVal(StateMgr.getSymbolManager(), R)
+ : UndefinedVal();
- St = BindInternal(St, Loc::MakeVal(MRMgr.getVarRegion(VD)), X);
+ St = BindInternal(St, Loc::MakeVal(R), X);
}
}
}
Modified: cfe/trunk/lib/Analysis/RegionStore.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/RegionStore.cpp?rev=62769&r1=62768&r2=62769&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/RegionStore.cpp (original)
+++ cfe/trunk/lib/Analysis/RegionStore.cpp Thu Jan 22 12:23:34 2009
@@ -552,8 +552,7 @@
// We treat function parameters as symbolic values.
if (const VarRegion* VR = dyn_cast<VarRegion>(R))
if (isa<ParmVarDecl>(VR->getDecl()))
- return SVal::MakeSymbolValue(getSymbolManager(), VR,
- VR->getRValueType(getContext()));
+ return SVal::GetRValueSymbolVal(getSymbolManager(), VR);
if (MRMgr.onStack(R) || MRMgr.onHeap(R)) {
// All stack variables are considered to have undefined values
@@ -564,8 +563,7 @@
}
// All other values are symbolic.
- return SVal::MakeSymbolValue(getSymbolManager(), R,
- cast<TypedRegion>(R)->getRValueType(getContext()));
+ return SVal::GetRValueSymbolVal(getSymbolManager(), R);
// FIXME: consider default values for elements and fields.
}
@@ -603,8 +601,7 @@
if (MRMgr.onStack(FR) || MRMgr.onHeap(FR))
FieldValue = UndefinedVal();
else
- FieldValue = SVal::MakeSymbolValue(getSymbolManager(), FR,
- FR->getRValueType(getContext()));
+ FieldValue = SVal::GetRValueSymbolVal(getSymbolManager(), FR);
}
StructVal = getBasicVals().consVals(FieldValue, StructVal);
Modified: cfe/trunk/lib/Analysis/SVals.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/SVals.cpp?rev=62769&r1=62768&r2=62769&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/SVals.cpp (original)
+++ cfe/trunk/lib/Analysis/SVals.cpp Thu Jan 22 12:23:34 2009
@@ -286,38 +286,14 @@
return nonloc::CompoundVal(BasicVals.getCompoundValData(T, Vals));
}
-SVal SVal::MakeSymbolValue(SymbolManager& SymMgr, const MemRegion* R,
- QualType T) {
- if (Loc::IsLocType(T))
- return Loc::MakeVal(SymMgr.getSymbol(R));
- else
- return NonLoc::MakeVal(SymMgr.getSymbol(R));
-}
-
-SVal SVal::GetSymbolValue(SymbolManager& SymMgr, VarDecl* D) {
-
- QualType T = D->getType();
+SVal SVal::GetRValueSymbolVal(SymbolManager& SymMgr, const MemRegion* R) {
+ SymbolRef sym = SymMgr.getRegionRValueSymbol(R);
+
+ if (const TypedRegion* TR = cast<TypedRegion>(R))
+ if (Loc::IsLocType(TR->getRValueType(SymMgr.getContext())))
+ return Loc::MakeVal(sym);
- if (Loc::IsLocType(T))
- return loc::SymbolVal(SymMgr.getSymbol(D));
-
- return nonloc::SymbolVal(SymMgr.getSymbol(D));
-}
-
-SVal SVal::getSymbolValue(SymbolManager& SymMgr, const MemRegion* R,
- const llvm::APSInt* Idx, QualType T) {
- if (Loc::IsLocType(T))
- return loc::SymbolVal(SymMgr.getElementSymbol(R, Idx));
- else
- return nonloc::SymbolVal(SymMgr.getElementSymbol(R, Idx));
-}
-
-SVal SVal::getSymbolValue(SymbolManager& SymMgr, const MemRegion* R,
- const FieldDecl* FD, QualType T) {
- if (Loc::IsLocType(T))
- return loc::SymbolVal(SymMgr.getFieldSymbol(R, FD));
- else
- return nonloc::SymbolVal(SymMgr.getFieldSymbol(R, FD));
+ return NonLoc::MakeVal(sym);
}
nonloc::LocAsInteger nonloc::LocAsInteger::Make(BasicValueFactory& Vals, Loc V,
Modified: cfe/trunk/lib/Analysis/SymbolManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/SymbolManager.cpp?rev=62769&r1=62768&r2=62769&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/SymbolManager.cpp (original)
+++ cfe/trunk/lib/Analysis/SymbolManager.cpp Thu Jan 22 12:23:34 2009
@@ -22,99 +22,23 @@
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);
- }
-
- DataSet.InsertNode(SD, InsertPos);
+ SymbolRegionRValue::Profile(profile, R);
+ void* InsertPos;
+ SymbolData* SD = DataSet.FindNodeOrInsertPos(profile, InsertPos);
+ if (SD) return SD->getSymbol();
- 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);
-
+ SD = (SymbolData*) BPAlloc.Allocate<SymbolRegionRValue>();
+ new (SD) SymbolRegionRValue(SymbolCounter, R);
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 @@
}
-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();
-
- case ConjuredKind:
- return cast<SymbolConjured>(this)->getType();
- }
+QualType SymbolConjured::getType(ASTContext&) const {
+ return T;
+}
+
+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 @@
return true;
}
-bool SymbolReaper::isLive(SymbolRef sym) {
+bool SymbolReaper::isLive(SymbolRef sym) {
return TheLiving.contains(sym);
}
More information about the cfe-commits
mailing list