aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2012-10-26 23:23:35 +0000
committerEli Friedman <eli.friedman@gmail.com>2012-10-26 23:23:35 +0000
commit3d7c780d93ebcb84a1224de8c44835ea43e82b15 (patch)
treee09f0b41899de083f34367ff644c4f0dbf279bc3
parent8c7a185dd84a7d44b1c83f66fd60629372efd498 (diff)
Add missing safety check to an optimization for do-while loops. PR14191.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166832 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/CGStmt.cpp4
-rw-r--r--test/CodeGen/dostmt.c10
2 files changed, 12 insertions, 2 deletions
diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp
index 7c65b3c437..5c1fea4472 100644
--- a/lib/CodeGen/CGStmt.cpp
+++ b/lib/CodeGen/CGStmt.cpp
@@ -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();
diff --git a/test/CodeGen/dostmt.c b/test/CodeGen/dostmt.c
index 1a2e02a78e..32e5f94034 100644
--- a/test/CodeGen/dostmt.c
+++ b/test/CodeGen/dostmt.c
@@ -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()
+}