[cfe-commits] r92102 - in /cfe/trunk: include/clang/Analysis/PathSensitive/GRExprEngine.h lib/Analysis/GRExprEngine.cpp test/Analysis/misc-ps-region-store.cpp
Ted Kremenek
kremenek at apple.com
Wed Dec 23 16:40:03 PST 2009
Author: kremenek
Date: Wed Dec 23 18:40:03 2009
New Revision: 92102
URL: http://llvm.org/viewvc/llvm-project?rev=92102&view=rev
Log:
Teach GRExprEngine to handle the initialization of the condition variable of a SwitchStmt.
Modified:
cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h
cfe/trunk/lib/Analysis/GRExprEngine.cpp
cfe/trunk/test/Analysis/misc-ps-region-store.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=92102&r1=92101&r2=92102&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h Wed Dec 23 18:40:03 2009
@@ -293,10 +293,10 @@
void VisitGuardedExpr(Expr* Ex, Expr* L, Expr* R, ExplodedNode* Pred,
ExplodedNodeSet& Dst);
- /// VisitIfStmtCondInit - Transfer function for handling the initialization
- /// of a condition variable in an IfStmt.
- void VisitIfStmtCondInit(IfStmt *IS, ExplodedNode *Pred,
- ExplodedNodeSet& Dst);
+ /// VisitCondInit - Transfer function for handling the initialization
+ /// of a condition variable in an IfStmt, SwitchStmt, etc.
+ void VisitCondInit(VarDecl *VD, Stmt *S, ExplodedNode *Pred,
+ ExplodedNodeSet& Dst);
void VisitInitListExpr(InitListExpr* E, ExplodedNode* Pred,
ExplodedNodeSet& Dst);
Modified: cfe/trunk/lib/Analysis/GRExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRExprEngine.cpp?rev=92102&r1=92101&r2=92102&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngine.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngine.cpp Wed Dec 23 18:40:03 2009
@@ -665,7 +665,7 @@
case Stmt::IfStmtClass:
// This case isn't for branch processing, but for handling the
// initialization of a condition variable.
- VisitIfStmtCondInit(cast<IfStmt>(S), Pred, Dst);
+ VisitCondInit(cast<IfStmt>(S)->getConditionVariable(), S, Pred, Dst);
break;
case Stmt::InitListExprClass:
@@ -733,6 +733,12 @@
case Stmt::StringLiteralClass:
VisitLValue(cast<StringLiteral>(S), Pred, Dst);
break;
+
+ case Stmt::SwitchStmtClass:
+ // This case isn't for branch processing, but for handling the
+ // initialization of a condition variable.
+ VisitCondInit(cast<SwitchStmt>(S)->getConditionVariable(), S, Pred, Dst);
+ break;
case Stmt::UnaryOperatorClass: {
UnaryOperator *U = cast<UnaryOperator>(S);
@@ -2230,12 +2236,10 @@
}
}
-void GRExprEngine::VisitIfStmtCondInit(IfStmt *IS, ExplodedNode *Pred,
- ExplodedNodeSet& Dst) {
-
- VarDecl* VD = IS->getConditionVariable();
- Expr* InitEx = VD->getInit();
+void GRExprEngine::VisitCondInit(VarDecl *VD, Stmt *S,
+ ExplodedNode *Pred, ExplodedNodeSet& Dst) {
+ Expr* InitEx = VD->getInit();
ExplodedNodeSet Tmp;
Visit(InitEx, Pred, Tmp);
@@ -2255,7 +2259,7 @@
Builder->getCurrentBlockCount());
}
- EvalBind(Dst, IS, IS, N, state,
+ EvalBind(Dst, S, S, N, state,
loc::MemRegionVal(state->getRegion(VD, LC)), InitVal, true);
}
}
Modified: cfe/trunk/test/Analysis/misc-ps-region-store.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-ps-region-store.cpp?rev=92102&r1=92101&r2=92102&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/misc-ps-region-store.cpp (original)
+++ cfe/trunk/test/Analysis/misc-ps-region-store.cpp Wed Dec 23 18:40:03 2009
@@ -41,3 +41,21 @@
}
return 0;
}
+
+int test_init_in_condition_switch() {
+ switch (int x = test_init_in_condition_aux()) { // no-warning
+ case 1:
+ return 0;
+ case 2:
+ if (x == 2)
+ return 0;
+ else {
+ // Unreachable.
+ int *p = 0;
+ *p = 0xDEADBEEF; // no-warning
+ }
+ default:
+ break;
+ }
+ return 0;
+}
More information about the cfe-commits
mailing list