]> granicus.if.org Git - clang/commitdiff
Move VLA processing logic from LiveVariables to CFG construction. This way all dataf...
authorTed Kremenek <kremenek@apple.com>
Fri, 26 Sep 2008 16:26:36 +0000 (16:26 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 26 Sep 2008 16:26:36 +0000 (16:26 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56655 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/CFG.cpp
lib/Analysis/LiveVariables.cpp

index b18f90497f06a520d66dcd140e4b85864e320bc9..c0b1b96967c4b0d22bc06e42db3e44a50c74979a 100644 (file)
@@ -467,6 +467,18 @@ CFGBlock* CFGBuilder::WalkAST(Stmt* Terminator, bool AlwaysAddStmt = false) {
   return WalkAST_VisitChildren(Terminator);
 }
 
+static VariableArrayType* FindVA(Type* t) {
+  while (ArrayType* vt = dyn_cast<ArrayType>(t)) {
+    if (VariableArrayType* vat = dyn_cast<VariableArrayType>(vt))
+      if (vat->getSizeExpr())
+        return vat;
+    
+    t = vt->getElementType().getTypePtr();
+  }
+  
+  return 0;
+}
+  
 /// WalkAST_VisitDeclSubExpr - Utility method to add block-level expressions
 ///  for initializers in Decls.
 CFGBlock* CFGBuilder::WalkAST_VisitDeclSubExpr(ScopedDecl* D) {
@@ -477,18 +489,22 @@ CFGBlock* CFGBuilder::WalkAST_VisitDeclSubExpr(ScopedDecl* D) {
   
   Expr* Init = VD->getInit();
   
-  if (!Init)
-    return Block;
-
-  // Optimization: Don't create separate block-level statements for literals.  
-  switch (Init->getStmtClass()) {
-    case Stmt::IntegerLiteralClass:
-    case Stmt::CharacterLiteralClass:
-    case Stmt::StringLiteralClass:
-      break;
-    default:
-      Block = addStmt(Init);
+  if (Init) {
+    // Optimization: Don't create separate block-level statements for literals.  
+    switch (Init->getStmtClass()) {
+      case Stmt::IntegerLiteralClass:
+      case Stmt::CharacterLiteralClass:
+      case Stmt::StringLiteralClass:
+        break;
+      default:
+        Block = addStmt(Init);
+    }
   }
+    
+  // If the type of VD is a VLA, then we must process its size expressions.
+  for (VariableArrayType* VA = FindVA(VD->getType().getTypePtr()); VA != 0;
+       VA = FindVA(VA->getElementType().getTypePtr()))
+    Block = addStmt(VA->getSizeExpr());  
   
   return Block;
 }
index e82c1e0bc01edfd609b5e859536896c389e4d754..58affbfcda51b4c89b7039e9dd4998f83bfc787e 100644 (file)
@@ -226,18 +226,6 @@ void TransferFuncs::VisitAssign(BinaryOperator* B) {
   Visit(B->getRHS());
 }
 
-static VariableArrayType* FindVA(Type* t) {
-  while (ArrayType* vt = dyn_cast<ArrayType>(t)) {
-    if (VariableArrayType* vat = dyn_cast<VariableArrayType>(vt))
-      if (vat->getSizeExpr())
-        return vat;
-    
-    t = vt->getElementType().getTypePtr();
-  }
-  
-  return NULL;
-}
-  
 void TransferFuncs::VisitDeclStmt(DeclStmt* DS) {
   // Declarations effectively "kill" a variable since they cannot
   // possibly be live before they are declared.
@@ -253,14 +241,6 @@ void TransferFuncs::VisitDeclStmt(DeclStmt* DS) {
       // Update liveness information by killing the VarDecl.
       unsigned bit = AD.getIdx(VD);
       LiveState.getDeclBit(bit) = Dead | AD.AlwaysLive.getDeclBit(bit);
-
-      // If the type of VD is a VLA, then we must process its size expressions.
-      // These expressions are evaluated before the variable comes into scope,
-      // so in a reverse dataflow analysis we evaluate them last.
-      for (VariableArrayType* VA = FindVA(VD->getType().getTypePtr()); VA != 0;
-           VA = FindVA(VA->getElementType().getTypePtr()))
-        Visit(VA->getSizeExpr());
-
     }
 }