diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp index b9c4eb3f43b..9d06a4f64be 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -1253,7 +1253,7 @@ static void mergeIncomingSwiftErrors(FunctionLoweringInfo *FuncInfo, FuncInfo->SwiftErrorMap[FuncInfo->MBB].push_back(VReg); MachineInstrBuilder SwiftErrorPHI = BuildMI(*FuncInfo->MBB, - FuncInfo->MBB->begin(), SDB->getCurDebugLoc(), + FuncInfo->InsertPt, SDB->getCurDebugLoc(), TII->get(TargetOpcode::PHI), VReg); for (const_pred_iterator PI = pred_begin(LLVMBB), PE = pred_end(LLVMBB); PI != PE; ++PI) { diff --git a/test/CodeGen/X86/swifterror.ll b/test/CodeGen/X86/swifterror.ll index d8db36b09c2..46dc1778bdc 100644 --- a/test/CodeGen/X86/swifterror.ll +++ b/test/CodeGen/X86/swifterror.ll @@ -357,3 +357,22 @@ handler2: ret float 1.0 } + +%swift.refcounted = type opaque + +; This test checks that we don't create bad phi nodes as part of swifterror +; isel. We used to fail machine ir verification. +; CHECK-APPLE: _swifterror_isel +; CHECK-O0: _swifterror_isel +define void @swifterror_isel(%swift.refcounted*) { +entry: + %swifterror = alloca swifterror %swift_error*, align 8 + br i1 undef, label %5, label %1 + + %2 = phi i16 [ %4, %1 ], [ undef, %entry ] + %3 = call i1 undef(i16 %2, %swift.refcounted* swiftself %0, %swift_error** nocapture swifterror %swifterror) + %4 = load i16, i16* undef, align 2 + br label %1 + + ret void +}