[cfe-commits] r92119 - in /cfe/trunk: include/clang/Analysis/Visitors/CFGRecStmtVisitor.h include/clang/Analysis/Visitors/CFGStmtVisitor.h lib/Analysis/LiveVariables.cpp
Ted Kremenek
kremenek at apple.com
Wed Dec 23 18:40:30 PST 2009
Author: kremenek
Date: Wed Dec 23 20:40:30 2009
New Revision: 92119
URL: http://llvm.org/viewvc/llvm-project?rev=92119&view=rev
Log:
Enhance dataflow analyses to recognize branch statements in the CFG used as hooks for the initialization of condition variables.
Modified:
cfe/trunk/include/clang/Analysis/Visitors/CFGRecStmtVisitor.h
cfe/trunk/include/clang/Analysis/Visitors/CFGStmtVisitor.h
cfe/trunk/lib/Analysis/LiveVariables.cpp
Modified: cfe/trunk/include/clang/Analysis/Visitors/CFGRecStmtVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Visitors/CFGRecStmtVisitor.h?rev=92119&r1=92118&r2=92119&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/Visitors/CFGRecStmtVisitor.h (original)
+++ cfe/trunk/include/clang/Analysis/Visitors/CFGRecStmtVisitor.h Wed Dec 23 20:40:30 2009
@@ -25,6 +25,25 @@
void VisitStmt(Stmt* S) {
static_cast< ImplClass* >(this)->VisitChildren(S);
}
+
+ void VisitConditionVariableInit(Stmt *S) {
+ assert(S == this->getCurrentBlkStmt());
+ VarDecl *CondVar = 0;
+ switch (S->getStmtClass()) {
+#define CONDVAR_CASE(CLASS) \
+case Stmt::CLASS ## Class:\
+CondVar = cast<CLASS>(S)->getConditionVariable();\
+break;
+ CONDVAR_CASE(IfStmt)
+ CONDVAR_CASE(ForStmt)
+ CONDVAR_CASE(SwitchStmt)
+ CONDVAR_CASE(WhileStmt)
+#undef CONDVAR_CASE
+ default:
+ assert(false && "Infeasible");
+ }
+ static_cast<ImplClass*>(this)->Visit(CondVar->getInit());
+ }
// Defining operator() allows the visitor to be used as a C++ style functor.
void operator()(Stmt* S) { static_cast<ImplClass*>(this)->BlockStmt_Visit(S);}
Modified: cfe/trunk/include/clang/Analysis/Visitors/CFGStmtVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Visitors/CFGStmtVisitor.h?rev=92119&r1=92118&r2=92119&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/Visitors/CFGStmtVisitor.h (original)
+++ cfe/trunk/include/clang/Analysis/Visitors/CFGStmtVisitor.h Wed Dec 23 20:40:30 2009
@@ -54,6 +54,13 @@
else
return RetTy();
}
+
+ /// VisitConditionVariableInit - Handle the initialization of condition
+ /// variables at branches. Valid statements include IfStmt, ForStmt,
+ /// WhileStmt, and SwitchStmt.
+ RetTy VisitConditionVariableInit(Stmt *S) {
+ return RetTy();
+ }
/// BlockVisit_XXX - Visitor methods for visiting the "root" statements in
/// CFGBlocks. Root statements are the statements that appear explicitly in
@@ -65,6 +72,11 @@
NullifyStmt cleanup(CurrentBlkStmt);
switch (S->getStmtClass()) {
+ case Stmt::IfStmtClass:
+ case Stmt::ForStmtClass:
+ case Stmt::WhileStmtClass:
+ case Stmt::SwitchStmtClass:
+ return static_cast<ImplClass*>(this)->VisitConditionVariableInit(S);
DISPATCH_CASE(StmtExpr)
DISPATCH_CASE(ConditionalOperator)
Modified: cfe/trunk/lib/Analysis/LiveVariables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/LiveVariables.cpp?rev=92119&r1=92118&r2=92119&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/LiveVariables.cpp (original)
+++ cfe/trunk/lib/Analysis/LiveVariables.cpp Wed Dec 23 20:40:30 2009
@@ -112,6 +112,11 @@
void VisitUnaryOperator(UnaryOperator* U);
void Visit(Stmt *S);
void VisitTerminator(CFGBlock* B);
+
+ /// VisitConditionVariableInit - Handle the initialization of condition
+ /// variables at branches. Valid statements include IfStmt, ForStmt,
+ /// WhileStmt, and SwitchStmt.
+ void VisitConditionVariableInit(Stmt *S);
void SetTopValue(LiveVariables::ValTy& V) {
V = AD.AlwaysLive;
@@ -126,7 +131,9 @@
if (AD.Observer)
AD.Observer->ObserveStmt(S,AD,LiveState);
- if (getCFG().isBlkExpr(S)) LiveState(S,AD) = Dead;
+ if (getCFG().isBlkExpr(S))
+ LiveState(S, AD) = Dead;
+
StmtVisitor<TransferFuncs,void>::Visit(S);
}
else if (!getCFG().isBlkExpr(S)) {
@@ -142,6 +149,11 @@
LiveState(S,AD) = Alive;
}
}
+
+void TransferFuncs::VisitConditionVariableInit(Stmt *S) {
+ assert(!getCFG().isBlkExpr(S));
+ CFGRecStmtVisitor<TransferFuncs>::VisitConditionVariableInit(S);
+}
void TransferFuncs::VisitTerminator(CFGBlock* B) {
More information about the cfe-commits
mailing list