[cfe-commits] r58419 - in /cfe/trunk: include/clang/Analysis/PathSensitive/GRExprEngine.h lib/Analysis/GRExprEngine.cpp
Zhongxing Xu
xuzhongxing at gmail.com
Wed Oct 29 22:02:23 PDT 2008
Author: zhongxingxu
Date: Thu Oct 30 00:02:23 2008
New Revision: 58419
URL: http://llvm.org/viewvc/llvm-project?rev=58419&view=rev
Log:
Implement VisitInitListExpr(). InitListExpr will have a nonloc::CompoundVal value.
Modified:
cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h
cfe/trunk/lib/Analysis/GRExprEngine.cpp
Modified: cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h?rev=58419&r1=58418&r2=58419&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h Thu Oct 30 00:02:23 2008
@@ -516,7 +516,9 @@
/// VisitGuardedExpr - Transfer function logic for ?, __builtin_choose
void VisitGuardedExpr(Expr* Ex, Expr* L, Expr* R, NodeTy* Pred, NodeSet& Dst);
-
+
+ void VisitInitListExpr(InitListExpr* E, NodeTy* Pred, NodeSet& Dst);
+
/// VisitLogicalExpr - Transfer function logic for '&&', '||'
void VisitLogicalExpr(BinaryOperator* B, NodeTy* Pred, NodeSet& Dst);
Modified: cfe/trunk/lib/Analysis/GRExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRExprEngine.cpp?rev=58419&r1=58418&r2=58419&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngine.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngine.cpp Thu Oct 30 00:02:23 2008
@@ -350,6 +350,10 @@
VisitCast(C, C->getSubExpr(), Pred, Dst);
break;
}
+
+ case Stmt::InitListExprClass:
+ VisitInitListExpr(cast<InitListExpr>(S), Pred, Dst);
+ break;
case Stmt::MemberExprClass:
VisitMemberExpr(cast<MemberExpr>(S), Pred, Dst, false);
@@ -1615,6 +1619,73 @@
}
}
+void GRExprEngine::VisitInitListExpr(InitListExpr* E, NodeTy* Pred,
+ NodeSet& Dst) {
+ const GRState* state = GetState(Pred);
+
+ QualType T = E->getType();
+
+ unsigned NumInitElements = E->getNumInits();
+
+ llvm::SmallVector<SVal, 10> InitVals;
+ InitVals.reserve(NumInitElements);
+
+
+ if (T->isArrayType()) {
+ for (unsigned i = 0; i < NumInitElements; ++i) {
+ Expr* Init = E->getInit(i);
+ NodeSet Tmp;
+ Visit(Init, Pred, Tmp);
+
+ // FIXME: Use worklist to allow state splitting.
+ assert(Tmp.size() == 1);
+
+ // Get the new intermediate node and its state.
+ Pred = *Tmp.begin();
+ state = GetState(Pred);
+
+ SVal InitV = GetSVal(state, Init);
+ InitVals.push_back(InitV);
+ }
+
+ // Now we have a vector holding all init values. Make CompoundSValData.
+ SVal V = NonLoc::MakeCompoundVal(T, &InitVals[0], NumInitElements,
+ StateMgr.getBasicVals());
+
+ // Make final state and node.
+ state = SetSVal(state, E, V);
+
+ MakeNode(Dst, E, Pred, state);
+ return;
+ }
+
+ if (T->isStructureType()) {
+ // FIXME: to be implemented.
+ MakeNode(Dst, E, Pred, state);
+ return;
+ }
+
+ if (Loc::IsLocType(T) || T->isIntegerType()) {
+ assert (E->getNumInits() == 1);
+ NodeSet Tmp;
+ Expr* Init = E->getInit(0);
+ Visit(Init, Pred, Tmp);
+ for (NodeSet::iterator I = Tmp.begin(), EI = Tmp.end(); I != EI; ++I) {
+ state = GetState(*I);
+ MakeNode(Dst, E, *I, SetSVal(state, E, GetSVal(state, Init)));
+ }
+ return;
+ }
+
+ if (T->isUnionType()) {
+ // FIXME: to be implemented.
+ MakeNode(Dst, E, Pred, state);
+ return;
+ }
+
+ printf("InitListExpr type = %s\n", T.getAsString().c_str());
+ assert(0 && "unprocessed InitListExpr type");
+}
/// VisitSizeOfAlignOfTypeExpr - Transfer function for sizeof(type).
void GRExprEngine::VisitSizeOfAlignOfTypeExpr(SizeOfAlignOfTypeExpr* Ex,
More information about the cfe-commits
mailing list