From: Ted Kremenek Date: Sat, 5 Nov 2011 00:26:53 +0000 (+0000) Subject: Teach LiveVariables to look through OpaqueValueExprs for extending Stmt liveness. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ddaec0dba69f2318d96f949b2f273b2befd1a5c2;p=clang Teach LiveVariables to look through OpaqueValueExprs for extending Stmt liveness. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143767 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/LiveVariables.cpp b/lib/Analysis/LiveVariables.cpp index 194c03cd0a..0b5a236bed 100644 --- a/lib/Analysis/LiveVariables.cpp +++ b/lib/Analysis/LiveVariables.cpp @@ -231,6 +231,30 @@ static const VariableArrayType *FindVA(QualType Ty) { return 0; } +static const Stmt *LookThroughStmt(const Stmt *S) { + while (S) { + switch (S->getStmtClass()) { + case Stmt::ParenExprClass: { + S = cast(S)->getSubExpr(); + continue; + } + case Stmt::OpaqueValueExprClass: { + S = cast(S)->getSourceExpr(); + continue; + } + default: + break; + } + } + return S; +} + +static void AddLiveStmt(llvm::ImmutableSet &Set, + llvm::ImmutableSet::Factory &F, + const Stmt *S) { + Set = F.add(Set, LookThroughStmt(S)); +} + void TransferFunctions::Visit(Stmt *S) { if (observer) observer->observeStmt(S, currentBlock, val); @@ -255,8 +279,7 @@ void TransferFunctions::Visit(Stmt *S) { // Include the implicit "this" pointer as being live. CXXMemberCallExpr *CE = cast(S); if (Expr *ImplicitObj = CE->getImplicitObjectArgument()) { - ImplicitObj = ImplicitObj->IgnoreParens(); - val.liveStmts = LV.SSetFact.add(val.liveStmts, ImplicitObj); + AddLiveStmt(val.liveStmts, LV.SSetFact, ImplicitObj); } break; } @@ -265,8 +288,7 @@ void TransferFunctions::Visit(Stmt *S) { if (const VarDecl *VD = dyn_cast(DS->getSingleDecl())) { for (const VariableArrayType* VA = FindVA(VD->getType()); VA != 0; VA = FindVA(VA->getElementType())) { - val.liveStmts = LV.SSetFact.add(val.liveStmts, - VA->getSizeExpr()->IgnoreParens()); + AddLiveStmt(val.liveStmts, LV.SSetFact, VA->getSizeExpr()); } } break; @@ -288,12 +310,8 @@ void TransferFunctions::Visit(Stmt *S) { for (Stmt::child_iterator it = S->child_begin(), ei = S->child_end(); it != ei; ++it) { - if (Stmt *child = *it) { - if (Expr *Ex = dyn_cast(child)) - child = Ex->IgnoreParens(); - - val.liveStmts = LV.SSetFact.add(val.liveStmts, child); - } + if (Stmt *child = *it) + AddLiveStmt(val.liveStmts, LV.SSetFact, child); } }