Finish the implementation of VisitCompoundLiteralExpr. As VisitInitListExpr is
available, things get much simplified.
One addition is that CompoundLiteralExpr can appear both in rvalue and lvalue
context.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58837 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/BasicStore.cpp b/lib/Analysis/BasicStore.cpp
index de5ff30..be9f4fd 100644
--- a/lib/Analysis/BasicStore.cpp
+++ b/lib/Analysis/BasicStore.cpp
@@ -46,13 +46,15 @@
return loc::MemRegionVal(MRMgr.getVarRegion(VD));
}
- Store BindCompoundLiteral(Store store, const CompoundLiteralRegion* R,
- const SVal* BegInit, const SVal* EndInit) {
+ Store BindCompoundLiteral(Store store, const CompoundLiteralExpr* CL,
+ SVal V) {
return store;
}
SVal getLValueVar(const GRState* St, const VarDecl* VD);
SVal getLValueString(const GRState* St, const StringLiteral* S);
+ SVal getLValueCompoundLiteral(const GRState* St,
+ 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);
@@ -99,7 +101,12 @@
const StringLiteral* S) {
return loc::MemRegionVal(MRMgr.getStringRegion(S));
}
-
+
+SVal BasicStoreManager::getLValueCompoundLiteral(const GRState* St,
+ const CompoundLiteralExpr* CL){
+ return loc::MemRegionVal(MRMgr.getCompoundLiteralRegion(CL));
+}
+
SVal BasicStoreManager::getLValueIvar(const GRState* St, const ObjCIvarDecl* D,
SVal Base) {
return UnknownVal();
diff --git a/lib/Analysis/GRExprEngine.cpp b/lib/Analysis/GRExprEngine.cpp
index 6162592..e2c23b4 100644
--- a/lib/Analysis/GRExprEngine.cpp
+++ b/lib/Analysis/GRExprEngine.cpp
@@ -329,6 +329,10 @@
case Stmt::CompoundAssignOperatorClass:
VisitBinaryOperator(cast<BinaryOperator>(S), Pred, Dst);
break;
+
+ case Stmt::CompoundLiteralExprClass:
+ VisitCompoundLiteralExpr(cast<CompoundLiteralExpr>(S), Pred, Dst, false);
+ break;
case Stmt::ConditionalOperatorClass: { // '?' operator
ConditionalOperator* C = cast<ConditionalOperator>(S);
@@ -435,7 +439,7 @@
return;
case Stmt::CompoundLiteralExprClass:
- VisitCompoundLiteralExpr(cast<CompoundLiteralExpr>(Ex), Pred, Dst);
+ VisitCompoundLiteralExpr(cast<CompoundLiteralExpr>(Ex), Pred, Dst, true);
return;
case Stmt::ObjCPropertyRefExprClass:
@@ -1575,31 +1579,21 @@
}
void GRExprEngine::VisitCompoundLiteralExpr(CompoundLiteralExpr* CL,
- NodeTy* Pred, NodeSet& Dst) {
-
- // FIXME: Can getInitializer() be NULL?
+ NodeTy* Pred, NodeSet& Dst,
+ bool asLValue) {
InitListExpr* ILE = cast<InitListExpr>(CL->getInitializer()->IgnoreParens());
NodeSet Tmp;
Visit(ILE, Pred, Tmp);
for (NodeSet::iterator I = Tmp.begin(), EI = Tmp.end(); I!=EI; ++I) {
- // Retrieve the initializer values from the environment and store them
- // into a vector that will then be handed off to the Store.
- const GRState* St = GetState(*I);
- llvm::SmallVector<SVal, 10> IVals;
- IVals.reserve(ILE->getNumInits());
-
- for (Stmt::child_iterator J=ILE->child_begin(), EJ=ILE->child_end();
- J!=EJ; ++J)
- IVals.push_back(GetSVal(St, cast<Expr>(*J)));
+ const GRState* St = GetState(*I);
+ SVal ILV = GetSVal(St, ILE);
+ St = StateMgr.BindCompoundLiteral(St, CL, ILV);
- const CompoundLiteralRegion* R =
- StateMgr.getRegionManager().getCompoundLiteralRegion(CL);
-
- assert (!IVals.empty() && "Initializer cannot be empty.");
-
- St = StateMgr.BindCompoundLiteral(St, R, &IVals[0], &IVals[0]+IVals.size());
- MakeNode(Dst, CL, *I, BindExpr(St, CL, loc::MemRegionVal(R)));
+ if (asLValue)
+ MakeNode(Dst, CL, *I, BindExpr(St, CL, StateMgr.GetLValue(St, CL)));
+ else
+ MakeNode(Dst, CL, *I, BindExpr(St, CL, ILV));
}
}
diff --git a/lib/Analysis/GRState.cpp b/lib/Analysis/GRState.cpp
index a5bc429..57f9c6b 100644
--- a/lib/Analysis/GRState.cpp
+++ b/lib/Analysis/GRState.cpp
@@ -96,11 +96,10 @@
/// array of initializer values.
const GRState*
GRStateManager::BindCompoundLiteral(const GRState* state,
- const CompoundLiteralRegion* R,
- const SVal* BegInit, const SVal* EndInit) {
+ const CompoundLiteralExpr* CL, SVal ILV) {
Store oldStore = state->getStore();
- Store newStore = StoreMgr->BindCompoundLiteral(oldStore, R, BegInit, EndInit);
+ Store newStore = StoreMgr->BindCompoundLiteral(oldStore, CL, ILV);
if (newStore == oldStore)
return state;
diff --git a/lib/Analysis/RegionStore.cpp b/lib/Analysis/RegionStore.cpp
index 2000d80..20a8ae0 100644
--- a/lib/Analysis/RegionStore.cpp
+++ b/lib/Analysis/RegionStore.cpp
@@ -46,17 +46,12 @@
return Retrieve(St, loc::MemRegionVal(R));
}
- Store BindCompoundLiteral(Store store, const CompoundLiteralRegion* R,
- const SVal* BegInit, const SVal* EndInit) {
-
- // FIXME: Let's discuss how we want to do the mapping in RegionStore
- // from CompoundLiteralRegion to values.
- assert (false && "Not yet implemented.");
- return store;
- }
+ Store BindCompoundLiteral(Store store, const CompoundLiteralExpr* CL, SVal V);
SVal getLValueString(const GRState* St, const StringLiteral* S);
+ SVal getLValueCompoundLiteral(const GRState* St, const CompoundLiteralExpr*);
+
SVal getLValueVar(const GRState* St, const VarDecl* VD);
SVal getLValueIvar(const GRState* St, const ObjCIvarDecl* D, SVal Base);
@@ -137,7 +132,12 @@
SVal RegionStoreManager::getLValueVar(const GRState* St, const VarDecl* VD) {
return loc::MemRegionVal(MRMgr.getVarRegion(VD));
}
-
+
+SVal RegionStoreManager::getLValueCompoundLiteral(const GRState* St,
+ const CompoundLiteralExpr* CL) {
+ return loc::MemRegionVal(MRMgr.getCompoundLiteralRegion(CL));
+}
+
SVal RegionStoreManager::getLValueIvar(const GRState* St, const ObjCIvarDecl* D,
SVal Base) {
return UnknownVal();
@@ -424,6 +424,14 @@
return store;
}
+Store RegionStoreManager::BindCompoundLiteral(Store store,
+ const CompoundLiteralExpr* CL,
+ SVal V) {
+ CompoundLiteralRegion* R = MRMgr.getCompoundLiteralRegion(CL);
+ store = Bind(store, loc::MemRegionVal(R), V);
+ return store;
+}
+
void RegionStoreManager::print(Store store, std::ostream& Out,
const char* nl, const char *sep) {
llvm::raw_os_ostream OS(Out);