Commit 8e554281 authored by Hans Wennborg's avatar Hans Wennborg
Browse files

Merging r276361:

------------------------------------------------------------------------
r276361 | wolfgangp | 2016-07-21 16:28:18 -0700 (Thu, 21 Jul 2016) | 5 lines

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: 276656
parent 76fe58b1
Loading
Loading
Loading
Loading
+1 −13
Original line number Diff line number Diff line
@@ -620,14 +620,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); 
  }

  // Emit the 'else' code if present.
  if (const Stmt *Else = S.getElse()) {
@@ -643,12 +636,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); 
    }
  }

+0 −36
Original line number Diff line number Diff line
// 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