[analyzer] Look up DynamicTypeInfo by region instead of symbol.
This allows us to store type info for non-symbolic regions. No functionality change. llvm-svn: 161811
This commit is contained in:
@@ -737,38 +737,34 @@ bool ProgramState::isTainted(SymbolRef Sym, TaintTagType Kind) const {
|
|||||||
/// symbol to it's most likely type.
|
/// symbol to it's most likely type.
|
||||||
namespace clang {
|
namespace clang {
|
||||||
namespace ento {
|
namespace ento {
|
||||||
struct DynamicTypeMap {};
|
typedef llvm::ImmutableMap<const MemRegion *, DynamicTypeInfo> DynamicTypeMap;
|
||||||
typedef llvm::ImmutableMap<SymbolRef, DynamicTypeInfo> DynamicTypeMapImpl;
|
|
||||||
template<> struct ProgramStateTrait<DynamicTypeMap>
|
template<> struct ProgramStateTrait<DynamicTypeMap>
|
||||||
: public ProgramStatePartialTrait<DynamicTypeMapImpl> {
|
: public ProgramStatePartialTrait<DynamicTypeMap> {
|
||||||
static void *GDMIndex() { static int index; return &index; }
|
static void *GDMIndex() { static int index; return &index; }
|
||||||
};
|
};
|
||||||
}}
|
}}
|
||||||
|
|
||||||
DynamicTypeInfo ProgramState::getDynamicTypeInfo(const MemRegion *Reg) const {
|
DynamicTypeInfo ProgramState::getDynamicTypeInfo(const MemRegion *Reg) const {
|
||||||
if (const TypedRegion *TR = dyn_cast<TypedRegion>(Reg))
|
|
||||||
return DynamicTypeInfo(TR->getLocationType());
|
|
||||||
|
|
||||||
if (const SymbolicRegion *SR = dyn_cast<SymbolicRegion>(Reg)) {
|
|
||||||
SymbolRef Sym = SR->getSymbol();
|
|
||||||
// Look up the dynamic type in the GDM.
|
// Look up the dynamic type in the GDM.
|
||||||
const DynamicTypeInfo *GDMType = get<DynamicTypeMap>(Sym);
|
const DynamicTypeInfo *GDMType = get<DynamicTypeMap>(Reg);
|
||||||
if (GDMType)
|
if (GDMType)
|
||||||
return *GDMType;
|
return *GDMType;
|
||||||
|
|
||||||
// Else, lookup the type at point of symbol creation.
|
// Otherwise, fall back to what we know about the region.
|
||||||
|
if (const TypedValueRegion *TR = dyn_cast<TypedValueRegion>(Reg))
|
||||||
|
return DynamicTypeInfo(TR->getValueType());
|
||||||
|
|
||||||
|
if (const SymbolicRegion *SR = dyn_cast<SymbolicRegion>(Reg)) {
|
||||||
|
SymbolRef Sym = SR->getSymbol();
|
||||||
return DynamicTypeInfo(Sym->getType(getStateManager().getContext()));
|
return DynamicTypeInfo(Sym->getType(getStateManager().getContext()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return DynamicTypeInfo();
|
return DynamicTypeInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
ProgramStateRef ProgramState::setDynamicTypeInfo(const MemRegion *Reg,
|
ProgramStateRef ProgramState::setDynamicTypeInfo(const MemRegion *Reg,
|
||||||
DynamicTypeInfo NewTy) const {
|
DynamicTypeInfo NewTy) const {
|
||||||
if (const SymbolicRegion *SR = dyn_cast<SymbolicRegion>(Reg)) {
|
ProgramStateRef NewState = set<DynamicTypeMap>(Reg, NewTy);
|
||||||
SymbolRef Sym = SR->getSymbol();
|
|
||||||
ProgramStateRef NewState = set<DynamicTypeMap>(Sym, NewTy);
|
|
||||||
assert(NewState);
|
assert(NewState);
|
||||||
return NewState;
|
return NewState;
|
||||||
}
|
}
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user