aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-05-04 06:18:28 +0000
committerTed Kremenek <kremenek@apple.com>2009-05-04 06:18:28 +0000
commitf936f4568700d799e7d92eecef67b0e2b822ae7e (patch)
tree2889e62f46d3d7af329d6e3d25a786b6534340cc /lib/Analysis
parent0c6db9417dceeb082296c4e097be5de3ee1c5eb7 (diff)
Per conversations with Zhongxing, add an 'element type' to
ElementRegion. I also removed 'ElementRegion::getArrayRegion', although we may need to add this back. This breaks a few test cases with RegionStore: - 'array-struct.c' triggers an infinite recursion in RegionStoreManager. Need to investigate. - misc-ps.m triggers a failure with RegionStoreManager as we now get the diagnostic: 'Line 159: Uninitialized or undefined return value returned to caller.' There were a bunch of places that needed to be edit RegionStoreManager, and we may not be passing all the correct 'element types' down from GRExprEngine. Zhongxing: When you get a chance, could you review this? I could have easily screwed up something basic in RegionStoreManager. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70830 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r--lib/Analysis/BasicStore.cpp11
-rw-r--r--lib/Analysis/GRExprEngine.cpp3
-rw-r--r--lib/Analysis/MemRegion.cpp25
-rw-r--r--lib/Analysis/RegionStore.cpp44
4 files changed, 44 insertions, 39 deletions
diff --git a/lib/Analysis/BasicStore.cpp b/lib/Analysis/BasicStore.cpp
index 6f31e7a01e..e4ac6b92a1 100644
--- a/lib/Analysis/BasicStore.cpp
+++ b/lib/Analysis/BasicStore.cpp
@@ -79,7 +79,8 @@ public:
const CompoundLiteralExpr* CL);
SVal getLValueIvar(const GRState* St, const ObjCIvarDecl* D, SVal Base);
SVal getLValueField(const GRState* St, SVal Base, const FieldDecl* D);
- SVal getLValueElement(const GRState* St, SVal Base, SVal Offset);
+ SVal getLValueElement(const GRState* St, QualType elementType,
+ SVal Base, SVal Offset);
/// ArrayToPointer - Used by GRExprEngine::VistCast to handle implicit
/// conversions between arrays and pointers.
@@ -193,8 +194,9 @@ SVal BasicStoreManager::getLValueField(const GRState* St, SVal Base,
return Loc::MakeVal(MRMgr.getFieldRegion(D, BaseR));
}
-SVal BasicStoreManager::getLValueElement(const GRState* St, SVal Base,
- SVal Offset) {
+SVal BasicStoreManager::getLValueElement(const GRState* St,
+ QualType elementType,
+ SVal Base, SVal Offset) {
if (Base.isUnknownOrUndef())
return Base;
@@ -246,7 +248,8 @@ SVal BasicStoreManager::getLValueElement(const GRState* St, SVal Base,
}
if (BaseR)
- return Loc::MakeVal(MRMgr.getElementRegion(UnknownVal(), BaseR));
+ return Loc::MakeVal(MRMgr.getElementRegion(elementType, UnknownVal(),
+ BaseR));
else
return UnknownVal();
}
diff --git a/lib/Analysis/GRExprEngine.cpp b/lib/Analysis/GRExprEngine.cpp
index 096ccddd08..0fabd35b0b 100644
--- a/lib/Analysis/GRExprEngine.cpp
+++ b/lib/Analysis/GRExprEngine.cpp
@@ -1011,7 +1011,8 @@ void GRExprEngine::VisitArraySubscriptExpr(ArraySubscriptExpr* A, NodeTy* Pred,
for (NodeSet::iterator I2=Tmp2.begin(), E2=Tmp2.end(); I2!=E2; ++I2) {
const GRState* state = GetState(*I2);
- SVal V = StateMgr.GetLValue(state, GetSVal(state, Base),
+ SVal V = StateMgr.GetLValue(state, A->getType(),
+ GetSVal(state, Base),
GetSVal(state, Idx));
if (asLValue)
diff --git a/lib/Analysis/MemRegion.cpp b/lib/Analysis/MemRegion.cpp
index 81855ba61b..78cd8146e4 100644
--- a/lib/Analysis/MemRegion.cpp
+++ b/lib/Analysis/MemRegion.cpp
@@ -96,15 +96,17 @@ void SymbolicRegion::Profile(llvm::FoldingSetNodeID& ID) const {
SymbolicRegion::ProfileRegion(ID, sym);
}
-void ElementRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, SVal Idx,
+void ElementRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
+ QualType ElementType, SVal Idx,
const MemRegion* superRegion) {
ID.AddInteger(MemRegion::ElementRegionKind);
+ ID.Add(ElementType);
ID.AddPointer(superRegion);
Idx.Profile(ID);
}
void ElementRegion::Profile(llvm::FoldingSetNodeID& ID) const {
- ElementRegion::ProfileRegion(ID, Index, superRegion);
+ ElementRegion::ProfileRegion(ID, ElementType, Index, superRegion);
}
void CodeTextRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, const void* data,
@@ -122,18 +124,6 @@ void CodeTextRegion::Profile(llvm::FoldingSetNodeID& ID) const {
// getLValueType() and getRValueType()
//===----------------------------------------------------------------------===//
-QualType ElementRegion::getRValueType(ASTContext& C) const {
- // Strip off typedefs from the ArrayRegion's RvalueType.
- QualType T = getArrayRegion()->getRValueType(C)->getDesugaredType();
-
- if (ArrayType* AT = dyn_cast<ArrayType>(T.getTypePtr()))
- return AT->getElementType();
-
- // If the RValueType of the array region isn't an ArrayType, then essentially
- // the element's
- return T;
-}
-
QualType StringRegion::getRValueType(ASTContext& C) const {
return Str->getType();
}
@@ -313,10 +303,11 @@ MemRegionManager::getCompoundLiteralRegion(const CompoundLiteralExpr* CL) {
}
ElementRegion*
-MemRegionManager::getElementRegion(SVal Idx, const TypedRegion* superRegion){
+MemRegionManager::getElementRegion(QualType elementType, SVal Idx,
+ const TypedRegion* superRegion){
llvm::FoldingSetNodeID ID;
- ElementRegion::ProfileRegion(ID, Idx, superRegion);
+ ElementRegion::ProfileRegion(ID, elementType, Idx, superRegion);
void* InsertPos;
MemRegion* data = Regions.FindNodeOrInsertPos(ID, InsertPos);
@@ -324,7 +315,7 @@ MemRegionManager::getElementRegion(SVal Idx, const TypedRegion* superRegion){
if (!R) {
R = (ElementRegion*) A.Allocate<ElementRegion>();
- new (R) ElementRegion(Idx, superRegion);
+ new (R) ElementRegion(elementType, Idx, superRegion);
Regions.InsertNode(R, InsertPos);
}
diff --git a/lib/Analysis/RegionStore.cpp b/lib/Analysis/RegionStore.cpp
index 8f573c3988..700174afb0 100644
--- a/lib/Analysis/RegionStore.cpp
+++ b/lib/Analysis/RegionStore.cpp
@@ -186,7 +186,8 @@ public:
SVal getLValueFieldOrIvar(const GRState* St, SVal Base, const Decl* D);
- SVal getLValueElement(const GRState* St, SVal Base, SVal Offset);
+ SVal getLValueElement(const GRState* St, QualType elementType,
+ SVal Base, SVal Offset);
SVal getSizeInElements(const GRState* St, const MemRegion* R);
@@ -383,7 +384,8 @@ SVal RegionStoreManager::getLValueFieldOrIvar(const GRState* St, SVal Base,
return loc::MemRegionVal(MRMgr.getFieldRegion(cast<FieldDecl>(D), BaseR));
}
-SVal RegionStoreManager::getLValueElement(const GRState* St,
+SVal RegionStoreManager::getLValueElement(const GRState* St,
+ QualType elementType,
SVal Base, SVal Offset) {
// If the base is an unknown or undefined value, just return it back.
@@ -430,7 +432,8 @@ SVal RegionStoreManager::getLValueElement(const GRState* St,
Offset = NonLoc::MakeVal(getBasicVals(), Tmp);
}
}
- return loc::MemRegionVal(MRMgr.getElementRegion(Offset, BaseRegion));
+ return loc::MemRegionVal(MRMgr.getElementRegion(elementType, Offset,
+ BaseRegion));
}
SVal BaseIdx = ElemR->getIndex();
@@ -447,7 +450,7 @@ SVal RegionStoreManager::getLValueElement(const GRState* St,
// can't we need to put a comment here. If it can, we should handle it.
assert(BaseIdxI.getBitWidth() >= OffI.getBitWidth());
- const TypedRegion *ArrayR = ElemR->getArrayRegion();
+ const TypedRegion *ArrayR = cast<TypedRegion>(ElemR->getSuperRegion());
SVal NewIdx;
if (OffI.isUnsigned() || OffI.getBitWidth() < BaseIdxI.getBitWidth()) {
@@ -465,7 +468,7 @@ SVal RegionStoreManager::getLValueElement(const GRState* St,
else
NewIdx = nonloc::ConcreteInt(getBasicVals().getValue(BaseIdxI + OffI));
- return loc::MemRegionVal(MRMgr.getElementRegion(NewIdx, ArrayR));
+ return loc::MemRegionVal(MRMgr.getElementRegion(elementType, NewIdx, ArrayR));
}
SVal RegionStoreManager::getSizeInElements(const GRState* St,
@@ -568,8 +571,13 @@ SVal RegionStoreManager::ArrayToPointer(Loc Array) {
if (!ArrayR)
return UnknownVal();
+ // Strip off typedefs from the ArrayRegion's RvalueType.
+ QualType T = ArrayR->getRValueType(getContext())->getDesugaredType();
+ ArrayType *AT = cast<ArrayType>(T);
+ T = AT->getElementType();
+
nonloc::ConcreteInt Idx(getBasicVals().getZeroWithPtrWidth(false));
- ElementRegion* ER = MRMgr.getElementRegion(Idx, ArrayR);
+ ElementRegion* ER = MRMgr.getElementRegion(T, Idx, ArrayR);
return loc::MemRegionVal(ER);
}
@@ -584,7 +592,6 @@ SVal RegionStoreManager::EvalBinOp(BinaryOperator::Opcode Op, Loc L, NonLoc R) {
return UnknownVal();
const TypedRegion* TR = cast<TypedRegion>(MR);
-
const ElementRegion* ER = dyn_cast<ElementRegion>(TR);
if (!ER) {
@@ -594,7 +601,7 @@ SVal RegionStoreManager::EvalBinOp(BinaryOperator::Opcode Op, Loc L, NonLoc R) {
// p += 3;
// Note that p binds to a TypedViewRegion(SymbolicRegion).
nonloc::ConcreteInt Idx(getBasicVals().getZeroWithPtrWidth(false));
- ER = MRMgr.getElementRegion(Idx, TR);
+ ER = MRMgr.getElementRegion(TR->getRValueType(getContext()), Idx, TR);
}
SVal Idx = ER->getIndex();
@@ -613,8 +620,9 @@ SVal RegionStoreManager::EvalBinOp(BinaryOperator::Opcode Op, Loc L, NonLoc R) {
nonloc::ConcreteInt OffConverted(getBasicVals().Convert(Base->getValue(),
Offset->getValue()));
SVal NewIdx = Base->EvalBinOp(getBasicVals(), Op, OffConverted);
- const MemRegion* NewER = MRMgr.getElementRegion(NewIdx,
- ER->getArrayRegion());
+ const MemRegion* NewER =
+ MRMgr.getElementRegion(ER->getElementType(), NewIdx,
+ cast<TypedRegion>(ER->getSuperRegion()));
return Loc::MakeVal(NewER);
}
@@ -769,15 +777,15 @@ SVal RegionStoreManager::RetrieveArray(const GRState* St, const TypedRegion* R){
ConstantArrayType* CAT = cast<ConstantArrayType>(T.getTypePtr());
llvm::ImmutableList<SVal> ArrayVal = getBasicVals().getEmptySValList();
-
llvm::APSInt Size(CAT->getSize(), false);
llvm::APSInt i = getBasicVals().getValue(0, Size.getBitWidth(),
Size.isUnsigned());
for (; i < Size; ++i) {
SVal Idx = NonLoc::MakeVal(getBasicVals(), i);
- ElementRegion* ER = MRMgr.getElementRegion(Idx, R);
- QualType ETy = ER->getRValueType(getContext());
+ ElementRegion* ER = MRMgr.getElementRegion(R->getRValueType(getContext()),
+ Idx, R);
+ QualType ETy = ER->getElementType();
SVal ElementVal = Retrieve(St, loc::MemRegionVal(ER), ETy);
ArrayVal = getBasicVals().consVals(ElementVal, ArrayVal);
}
@@ -1059,7 +1067,9 @@ const GRState* RegionStoreManager::BindArray(const GRState* St,
break;
SVal Idx = NonLoc::MakeVal(getBasicVals(), i);
- ElementRegion* ER = MRMgr.getElementRegion(Idx, R);
+ ElementRegion* ER =
+ MRMgr.getElementRegion(cast<ArrayType>(T)->getElementType(),
+ Idx, R);
SVal V = NonLoc::MakeVal(getBasicVals(), str[j], sizeof(char)*8, true);
St = Bind(St, loc::MemRegionVal(ER), V);
@@ -1068,9 +1078,7 @@ const GRState* RegionStoreManager::BindArray(const GRState* St,
return St;
}
-
nonloc::CompoundVal& CV = cast<nonloc::CompoundVal>(Init);
-
nonloc::CompoundVal::iterator VI = CV.begin(), VE = CV.end();
for (; i < Size; ++i, ++VI) {
@@ -1079,7 +1087,9 @@ const GRState* RegionStoreManager::BindArray(const GRState* St,
break;
SVal Idx = NonLoc::MakeVal(getBasicVals(), i);
- ElementRegion* ER = MRMgr.getElementRegion(Idx, R);
+ ElementRegion* ER =
+ MRMgr.getElementRegion(cast<ArrayType>(T)->getElementType(),
+ Idx, R);
if (CAT->getElementType()->isStructureType())
St = BindStruct(St, ER, *VI);