[cfe-commits] r166832 - in /cfe/trunk: lib/CodeGen/CGStmt.cpp test/CodeGen/dostmt.c

Eli Friedman eli.friedman at gmail.com
Fri Oct 26 16:23:35 PDT 2012


Author: efriedma
Date: Fri Oct 26 18:23:35 2012
New Revision: 166832

URL: http://llvm.org/viewvc/llvm-project?rev=166832&view=rev
Log:
Add missing safety check to an optimization for do-while loops.  PR14191.


Modified:
    cfe/trunk/lib/CodeGen/CGStmt.cpp
    cfe/trunk/test/CodeGen/dostmt.c

Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=166832&r1=166831&r2=166832&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Fri Oct 26 18:23:35 2012
@@ -237,6 +237,10 @@
   if (!BI || !BI->isUnconditional())
     return;
 
+  // Can only simplify empty blocks.
+  if (BI != BB->begin())
+    return;
+
   BB->replaceAllUsesWith(BI->getSuccessor(0));
   BI->eraseFromParent();
   BB->eraseFromParent();

Modified: cfe/trunk/test/CodeGen/dostmt.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/dostmt.c?rev=166832&r1=166831&r2=166832&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/dostmt.c (original)
+++ cfe/trunk/test/CodeGen/dostmt.c Fri Oct 26 18:23:35 2012
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -emit-llvm -o -
+// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
 
 int bar();
 int test0() {
@@ -66,5 +66,11 @@
   do { break; } while(0);
 }
 
- 
+// PR14191
+void test6f(void);
+void test6() {
+  do {
+  } while (test6f(), 0);
+  // CHECK call void @test6f()
+}
 





More information about the cfe-commits mailing list