summaryrefslogtreecommitdiffstats
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
commitfc5b2effcf0e37e9aec1dc2a40b07989ae5b9a00 (patch)
treed5f30e99eebfd94fa109cd958cc4e2e3b6767290
parenta7137bc1c2eb8d4347e2de51fc7dd206029286a5 (diff)
downloadbcm5719-llvm-fc5b2effcf0e37e9aec1dc2a40b07989ae5b9a00.tar.gz
bcm5719-llvm-fc5b2effcf0e37e9aec1dc2a40b07989ae5b9a00.zip
Add missing safety check to an optimization for do-while loops. PR14191.
llvm-svn: 166832
-rw-r--r--clang/lib/CodeGen/CGStmt.cpp4
-rw-r--r--clang/test/CodeGen/dostmt.c10
2 files changed, 12 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 7c65b3c4376..5c1fea4472f 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/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/clang/test/CodeGen/dostmt.c b/clang/test/CodeGen/dostmt.c
index 1a2e02a78e6..32e5f94034f 100644
--- a/clang/test/CodeGen/dostmt.c
+++ b/clang/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()
+}
OpenPOWER on IntegriCloud