]> granicus.if.org Git - clang/commitdiff
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)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166832 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 7c65b3c4376a43403443cf8d368cfcbe17f8c85f..5c1fea4472fb1dc1709111144e4d1ed338dcb24c 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 1a2e02a78e6ba60cab34d9b6d32be8e5bd1a726e..32e5f94034facd67acba6d2180c16cca8e645549 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()
+}