From: Eli Friedman Date: Fri, 26 Oct 2012 23:23:35 +0000 (+0000) Subject: Add missing safety check to an optimization for do-while loops. PR14191. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3d7c780d93ebcb84a1224de8c44835ea43e82b15;p=clang 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 --- 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() +}