[cfe-commits] r56706 - in /cfe/trunk: lib/AST/CFG.cpp test/Analysis/dead-stores.c

Ted Kremenek kremenek at apple.com
Fri Sep 26 15:58:58 PDT 2008


Author: kremenek
Date: Fri Sep 26 17:58:57 2008
New Revision: 56706

URL: http://llvm.org/viewvc/llvm-project?rev=56706&view=rev
Log:
Add CFG support for implicit-control flow for VLA size expressions within an SizeOfAlignOfTypeExpr.

Modified:
    cfe/trunk/lib/AST/CFG.cpp
    cfe/trunk/test/Analysis/dead-stores.c

Modified: cfe/trunk/lib/AST/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CFG.cpp?rev=56706&r1=56705&r2=56706&view=diff

==============================================================================
--- cfe/trunk/lib/AST/CFG.cpp (original)
+++ cfe/trunk/lib/AST/CFG.cpp Fri Sep 26 17:58:57 2008
@@ -180,6 +180,18 @@
   
   bool badCFG;
 };
+  
+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;
+}
     
 /// BuildCFG - Constructs a CFG from an AST (a Stmt*).  The AST can
 ///  represent an arbitrary statement.  Examples include a single expression
@@ -405,6 +417,17 @@
     case Stmt::StmtExprClass:
       return WalkAST_VisitStmtExpr(cast<StmtExpr>(Terminator));
 
+    case Stmt::SizeOfAlignOfTypeExprClass: {
+      SizeOfAlignOfTypeExpr* E = cast<SizeOfAlignOfTypeExpr>(Terminator);
+
+      // VLA types have expressions that must be evaluated.
+      for (VariableArrayType* VA = FindVA(E->getArgumentType().getTypePtr());
+           VA != 0; VA = FindVA(VA->getElementType().getTypePtr()))
+        addStmt(VA->getSizeExpr());
+
+      return Block;
+    }
+      
     case Stmt::UnaryOperatorClass: {
       UnaryOperator* U = cast<UnaryOperator>(Terminator);
       
@@ -475,18 +498,6 @@
   if (AlwaysAddStmt) Block->appendStmt(Terminator);
   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.

Modified: cfe/trunk/test/Analysis/dead-stores.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/dead-stores.c?rev=56706&r1=56705&r2=56706&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/dead-stores.c (original)
+++ cfe/trunk/test/Analysis/dead-stores.c Fri Sep 26 17:58:57 2008
@@ -66,7 +66,6 @@
   return 1;
 }
 
-
 int f10() {
   int x = 4;
   x = 10 + x; // expected-warning{{never read}}
@@ -115,3 +114,9 @@
   int z[count];
 }
 
+int f16(int x) {
+  x = x * 2;
+  x = sizeof(int [x = (x || x + 1) * 2]);  // expected-warning{{Although the value stored to 'x' is used}}
+  return x;
+}
+





More information about the cfe-commits mailing list