[cfe-commits] r153242 - in /cfe/trunk: lib/Analysis/CFG.cpp test/SemaCXX/uninitialized.cpp

Ted Kremenek kremenek at apple.com
Wed Mar 21 22:57:44 PDT 2012


Author: kremenek
Date: Thu Mar 22 00:57:43 2012
New Revision: 153242

URL: http://llvm.org/viewvc/llvm-project?rev=153242&view=rev
Log:
Fix broken CFG when an initializer is a statement expression that starts with a while loop (PR 12325).

Modified:
    cfe/trunk/lib/Analysis/CFG.cpp
    cfe/trunk/test/SemaCXX/uninitialized.cpp

Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=153242&r1=153241&r2=153242&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Thu Mar 22 00:57:43 2012
@@ -1464,14 +1464,24 @@
 
   autoCreateBlock();
   appendStmt(Block, DS);
+  
+  // Keep track of the last non-null block, as 'Block' can be nulled out
+  // if the initializer expression is something like a 'while' in a
+  // statement-expression.
+  CFGBlock *LastBlock = Block;
 
   if (Init) {
-    if (HasTemporaries)
+    if (HasTemporaries) {
       // For expression with temporaries go directly to subexpression to omit
       // generating destructors for the second time.
-      Visit(cast<ExprWithCleanups>(Init)->getSubExpr());
-    else
-      Visit(Init);
+      ExprWithCleanups *EC = cast<ExprWithCleanups>(Init);
+      if (CFGBlock *newBlock = Visit(EC->getSubExpr()))
+        LastBlock = newBlock;
+    }
+    else {
+      if (CFGBlock *newBlock = Visit(Init))
+        LastBlock = newBlock;
+    }
   }
 
   // If the type of VD is a VLA, then we must process its size expressions.
@@ -1483,7 +1493,7 @@
   if (ScopePos && VD == *ScopePos)
     ++ScopePos;
 
-  return Block;
+  return Block ? Block : LastBlock;
 }
 
 CFGBlock *CFGBuilder::VisitIfStmt(IfStmt *I) {

Modified: cfe/trunk/test/SemaCXX/uninitialized.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/uninitialized.cpp?rev=153242&r1=153241&r2=153242&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/uninitialized.cpp (original)
+++ cfe/trunk/test/SemaCXX/uninitialized.cpp Thu Mar 22 00:57:43 2012
@@ -147,3 +147,18 @@
     (void)y;
   };
 }
+
+// PR 12325 - this was a false uninitialized value warning due to
+// a broken CFG.
+int pr12325(int params) {
+  int x = ({
+    while (false)
+      ;
+    int _v = params;
+    if (false)
+      ;
+    _v; // no-warning
+  });
+  return x;
+}
+





More information about the cfe-commits mailing list