[cfe-commits] r143767 - /cfe/trunk/lib/Analysis/LiveVariables.cpp

Ted Kremenek kremenek at apple.com
Fri Nov 4 17:26:53 PDT 2011


Author: kremenek
Date: Fri Nov  4 19:26:53 2011
New Revision: 143767

URL: http://llvm.org/viewvc/llvm-project?rev=143767&view=rev
Log:
Teach LiveVariables to look through OpaqueValueExprs for extending Stmt liveness.

Modified:
    cfe/trunk/lib/Analysis/LiveVariables.cpp

Modified: cfe/trunk/lib/Analysis/LiveVariables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/LiveVariables.cpp?rev=143767&r1=143766&r2=143767&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/LiveVariables.cpp (original)
+++ cfe/trunk/lib/Analysis/LiveVariables.cpp Fri Nov  4 19:26:53 2011
@@ -231,6 +231,30 @@
   return 0;
 }
 
+static const Stmt *LookThroughStmt(const Stmt *S) {
+  while (S) {
+    switch (S->getStmtClass()) {
+      case Stmt::ParenExprClass: {
+        S = cast<ParenExpr>(S)->getSubExpr();
+        continue;
+      }
+      case Stmt::OpaqueValueExprClass: {
+        S = cast<OpaqueValueExpr>(S)->getSourceExpr();
+        continue;
+      }
+      default:
+        break;
+    }
+  }
+  return S;
+}
+
+static void AddLiveStmt(llvm::ImmutableSet<const Stmt *> &Set,
+                        llvm::ImmutableSet<const Stmt *>::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 @@
       // Include the implicit "this" pointer as being live.
       CXXMemberCallExpr *CE = cast<CXXMemberCallExpr>(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 @@
       if (const VarDecl *VD = dyn_cast<VarDecl>(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 @@
   
   for (Stmt::child_iterator it = S->child_begin(), ei = S->child_end();
        it != ei; ++it) {
-    if (Stmt *child = *it) {
-      if (Expr *Ex = dyn_cast<Expr>(child))
-        child = Ex->IgnoreParens();
-               
-      val.liveStmts = LV.SSetFact.add(val.liveStmts, child);
-    }
+    if (Stmt *child = *it)
+      AddLiveStmt(val.liveStmts, LV.SSetFact, child);
   }
 }
 





More information about the cfe-commits mailing list