Add missing safety check to an optimization for do-while loops. PR14191.
authorEli Friedman <eli.friedman@gmail.com>
Fri, 26 Oct 2012 23:23:35 +0000 (23:23 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Fri, 26 Oct 2012 23:23:35 +0000 (23:23 +0000)
llvm-svn: 166832

clang/lib/CodeGen/CGStmt.cpp
clang/test/CodeGen/dostmt.c

index 7c65b3c..5c1fea4 100644 (file)
@@ -237,6 +237,10 @@ void CodeGenFunction::SimplifyForwardingBlocks(llvm::BasicBlock *BB) {
   if (!BI || !BI->isUnconditional())
     return;
 
+  // Can only simplify empty blocks.
+  if (BI != BB->begin())
+    return;
+
   BB->replaceAllUsesWith(BI->getSuccessor(0));
   BI->eraseFromParent();
   BB->eraseFromParent();
index 1a2e02a..32e5f94 100644 (file)
@@ -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 @@ void test5() {
   do { break; } while(0);
 }
 
+// PR14191
+void test6f(void);
+void test6() {
+  do {
+  } while (test6f(), 0);
+  // CHECK call void @test6f()
+}