From 5cd24389afe21db6f246c20a1f49461fca0b31cb Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 16 Apr 2008 17:07:59 +0000 Subject: [PATCH] LiveVariables now updates the liveness state of block-level expressions that are referenced by CFGBlock terminators. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49798 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/LiveVariables.cpp | 61 +++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 12 deletions(-) diff --git a/lib/Analysis/LiveVariables.cpp b/lib/Analysis/LiveVariables.cpp index 7896bfcfb0..feba80d695 100644 --- a/lib/Analysis/LiveVariables.cpp +++ b/lib/Analysis/LiveVariables.cpp @@ -143,22 +143,59 @@ void TransferFuncs::Visit(Stmt *S) { } void TransferFuncs::VisitTerminator(Stmt* S) { - return; - for (Stmt::child_iterator I = S->child_begin(), E = S->child_end(); - I != E; ++I) { - - Stmt* Child = *I; - if (!Child) continue; - - if (getCFG().isBlkExpr(Child)) { - LiveState(Child, AD) = Alive; - return; // Only one "condition" expression. - } + Expr* E = NULL; + + switch (S->getStmtClass()) { + default: + return; + + case Stmt::ForStmtClass: + E = cast(S)->getCond(); + break; + + case Stmt::WhileStmtClass: + E = cast(S)->getCond(); + break; + + case Stmt::DoStmtClass: + E = cast(S)->getCond(); + break; + + case Stmt::IfStmtClass: + E = cast(S)->getCond(); + break; + + case Stmt::ChooseExprClass: + E = cast(S)->getCond(); + break; + + case Stmt::IndirectGotoStmtClass: + E = cast(S)->getTarget(); + break; + + case Stmt::SwitchStmtClass: + E = cast(S)->getCond(); + break; + + case Stmt::ConditionalOperatorClass: + E = cast(S)->getCond(); + break; + + case Stmt::BinaryOperatorClass: // '&&' and '||' + E = cast(S)->getLHS(); + break; } + + if (!E) + return; + + E = E->IgnoreParens(); + + assert (getCFG().isBlkExpr(E)); + LiveState(E, AD) = Alive; } - void TransferFuncs::VisitDeclRefExpr(DeclRefExpr* DR) { if (VarDecl* V = dyn_cast(DR->getDecl())) LiveState(V,AD) = Alive;