From 24e03341af566cde6c368241ff36e91ac539a374 Mon Sep 17 00:00:00 2001 From: Wolfgang Pieb Date: Thu, 21 Jul 2016 23:28:18 +0000 Subject: [PATCH] Reverting r275115 which caused PR28634. When empty (forwarding) basic blocks that are referenced by user labels are removed, incorrect code may be generated. llvm-svn: 276361 --- clang/lib/CodeGen/CGStmt.cpp | 14 +----------- clang/test/CodeGen/forwarding-blocks-if.c | 36 ------------------------------- 2 files changed, 1 insertion(+), 49 deletions(-) delete mode 100644 clang/test/CodeGen/forwarding-blocks-if.c diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp index 31f1982..2adb177 100644 --- a/clang/lib/CodeGen/CGStmt.cpp +++ b/clang/lib/CodeGen/CGStmt.cpp @@ -623,14 +623,7 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) { RunCleanupsScope ThenScope(*this); EmitStmt(S.getThen()); } - { - auto CurBlock = Builder.GetInsertBlock(); - EmitBranch(ContBlock); - // Eliminate any empty blocks that may have been created by nested - // control flow statements in the 'then' clause. - if (CurBlock) - SimplifyForwardingBlocks(CurBlock); - } + EmitBranch(ContBlock); // Emit the 'else' code if present. if (const Stmt *Else = S.getElse()) { @@ -646,12 +639,7 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) { { // There is no need to emit line number for an unconditional branch. auto NL = ApplyDebugLocation::CreateEmpty(*this); - auto CurBlock = Builder.GetInsertBlock(); EmitBranch(ContBlock); - // Eliminate any empty blocks that may have been created by nested - // control flow statements emitted in the 'else' clause. - if (CurBlock) - SimplifyForwardingBlocks(CurBlock); } } diff --git a/clang/test/CodeGen/forwarding-blocks-if.c b/clang/test/CodeGen/forwarding-blocks-if.c deleted file mode 100644 index 51711bf..0000000 --- a/clang/test/CodeGen/forwarding-blocks-if.c +++ /dev/null @@ -1,36 +0,0 @@ -// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s -// Check that no empty blocks are generated for nested ifs. - -extern void func(); - -int f0(int val) { - if (val == 0) { - func(); - } else if (val == 1) { - func(); - } - return 0; -} - -// CHECK-LABEL: define {{.*}}i32 @f0 -// CHECK: call void {{.*}} @func -// CHECK: call void {{.*}} @func -// CHECK: br label %[[RETBLOCK1:[^ ]*]] -// CHECK: [[RETBLOCK1]]: -// CHECK-NOT: br label -// CHECK: ret i32 - -int f1(int val, int g) { - if (val == 0) - if (g == 1) { - func(); - } - return 0; -} - -// CHECK-LABEL: define {{.*}}i32 @f1 -// CHECK: call void {{.*}} @func -// CHECK: br label %[[RETBLOCK2:[^ ]*]] -// CHECK: [[RETBLOCK2]]: -// CHECK-NOT: br label -// CHECK: ret i32 -- 2.7.4