]> granicus.if.org Git - clang/commitdiff
Fix horrible CFG bug caused by a series of NullStmts appearing at the beginning of...
authorTed Kremenek <kremenek@apple.com>
Tue, 17 Aug 2010 21:00:06 +0000 (21:00 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 17 Aug 2010 21:00:06 +0000 (21:00 +0000)
the body of the DoStmt to be disconnected from the preceding code.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111283 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/CFG.cpp
test/Analysis/dead-stores.c

index 1d5d8521ad5f5a01d09f9977d78071d8890a26d9..da7f36a132c67cb9c5759e46e77cae25857c3633 100644 (file)
@@ -702,7 +702,10 @@ CFGBlock* CFGBuilder::VisitCompoundStmt(CompoundStmt* C) {
 
   for (CompoundStmt::reverse_body_iterator I=C->body_rbegin(), E=C->body_rend();
        I != E; ++I ) {
-    LastBlock = addStmt(*I);
+    // If we hit a segment of code just containing ';' (NullStmts), we can
+    // get a null block back.  In such cases, just use the LastBlock
+    if (CFGBlock *newBlock = addStmt(*I))
+      LastBlock = newBlock;
 
     if (badCFG)
       return NULL;
index 3cd061271f4b9a41022e63926a6810fc95cbf3eb..46b4038ccec8ffc8e4c009ee90256d61ef1c1f48 100644 (file)
@@ -462,3 +462,27 @@ void rdar8014335() {
   }
 }
 
+// <rdar://problem/8320674> NullStmts followed by do...while() can lead to disconnected CFG
+//
+// This previously caused bogus dead-stores warnings because the body of the first do...while was
+// disconnected from the entry of the function.
+typedef struct { float r; float i; } s_rdar8320674;
+typedef struct { s_rdar8320674 x[1]; } s2_rdar8320674;
+
+void rdar8320674(s_rdar8320674 *z, unsigned y, s2_rdar8320674 *st, int m)
+{
+    s_rdar8320674 * z2;
+    s_rdar8320674 * tw1 = st->x;
+    s_rdar8320674 t;
+    z2 = z + m;
+    do{
+        ; ;
+        do{ (t).r = (*z2).r*(*tw1).r - (*z2).i*(*tw1).i; (t).i = (*z2).r*(*tw1).i + (*z2).i*(*tw1).r; }while(0);
+        tw1 += y;
+        do { (*z2).r=(*z).r-(t).r; (*z2).i=(*z).i-(t).i; }while(0);
+        do { (*z).r += (t).r; (*z).i += (t).i; }while(0);
+        ++z2;
+        ++z;
+    }while (--m);
+}
+