forked from OSchip/llvm-project
Add SymbolData for array elements and struct fields.
llvm-svn: 59618
This commit is contained in:
parent
2ae21ee517
commit
b8e54884c8
|
@ -73,6 +73,10 @@ public:
|
|||
}
|
||||
|
||||
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);
|
||||
|
||||
inline bool isUnknown() const {
|
||||
return getRawKind() == UnknownKind;
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
namespace clang {
|
||||
|
||||
|
||||
class MemRegion;
|
||||
class SymbolManager;
|
||||
|
||||
class SymbolID {
|
||||
|
@ -69,7 +69,8 @@ namespace clang {
|
|||
|
||||
class SymbolData : public llvm::FoldingSetNode {
|
||||
public:
|
||||
enum Kind { UndefKind, ParmKind, GlobalKind, ContentsOfKind, ConjuredKind };
|
||||
enum Kind { UndefKind, ParmKind, GlobalKind, ElementKind, FieldKind,
|
||||
ContentsOfKind, ConjuredKind };
|
||||
|
||||
private:
|
||||
Kind K;
|
||||
|
@ -141,6 +142,52 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class SymbolDataElement : public SymbolData {
|
||||
const MemRegion* R;
|
||||
const llvm::APSInt* Idx;
|
||||
|
||||
public:
|
||||
SymbolDataElement(SymbolID 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(SymbolID 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;
|
||||
}
|
||||
};
|
||||
|
||||
class SymbolDataContentsOf : public SymbolData {
|
||||
SymbolID Sym;
|
||||
|
||||
|
@ -245,6 +292,8 @@ public:
|
|||
~SymbolManager();
|
||||
|
||||
SymbolID getSymbol(VarDecl* D);
|
||||
SymbolID getElementSymbol(const MemRegion* R, const llvm::APSInt* Idx);
|
||||
SymbolID getFieldSymbol(const MemRegion* R, const FieldDecl* D);
|
||||
SymbolID getContentsOfSymbol(SymbolID sym);
|
||||
SymbolID getConjuredSymbol(Stmt* E, QualType T, unsigned VisitCount);
|
||||
SymbolID getConjuredSymbol(Expr* E, unsigned VisitCount) {
|
||||
|
|
|
@ -272,6 +272,22 @@ SVal SVal::GetSymbolValue(SymbolManager& SymMgr, VarDecl* 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));
|
||||
}
|
||||
|
||||
nonloc::LocAsInteger nonloc::LocAsInteger::Make(BasicValueFactory& Vals, Loc V,
|
||||
unsigned Bits) {
|
||||
return LocAsInteger(Vals.getPersistentSValWithData(V, Bits));
|
||||
|
|
|
@ -51,6 +51,41 @@ SymbolID SymbolManager::getSymbol(VarDecl* D) {
|
|||
DataMap[SymbolCounter] = SD;
|
||||
return SymbolCounter++;
|
||||
}
|
||||
|
||||
SymbolID 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;
|
||||
return SymbolCounter++;
|
||||
}
|
||||
|
||||
SymbolID 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++;
|
||||
}
|
||||
|
||||
SymbolID SymbolManager::getContentsOfSymbol(SymbolID sym) {
|
||||
|
||||
|
|
Loading…
Reference in New Issue