Skip to content

Commit 84a43e0

Browse files
committed
[llvm][SelectionDAG] Fix up chains in lowerInvokeable. rdar://113994760
lowerInvokeable wasn't updating the returned chain after emitting the lowerEndEH, which caused SwiftErrorVal-handling code to re-set the DAG root, and thus accidentally skip the EH_LABEL node it was supposed to have addeed. After fixing that, a few places needed to be adjusted that assume the specific shape of the returned DAG. Fixes: #64826 Fixes: rdar://113994760
1 parent c5e417a commit 84a43e0

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8592,6 +8592,7 @@ SelectionDAGBuilder::lowerInvokable(TargetLowering::CallLoweringInfo &CLI,
85928592
if (EHPadBB) {
85938593
DAG.setRoot(lowerEndEH(getRoot(), cast_or_null<InvokeInst>(CLI.CB), EHPadBB,
85948594
BeginLabel));
8595+
Result.second = getRoot();
85958596
}
85968597

85978598
return Result;
@@ -10389,6 +10390,8 @@ void SelectionDAGBuilder::visitPatchpoint(const CallBase &CB,
1038910390
std::pair<SDValue, SDValue> Result = lowerInvokable(CLI, EHPadBB);
1039010391

1039110392
SDNode *CallEnd = Result.second.getNode();
10393+
if (CallEnd->getOpcode() == ISD::EH_LABEL)
10394+
CallEnd = CallEnd->getOperand(0).getNode();
1039210395
if (HasDef && (CallEnd->getOpcode() == ISD::CopyFromReg))
1039310396
CallEnd = CallEnd->getOperand(0).getNode();
1039410397

llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,9 @@ static std::pair<SDValue, SDNode *> lowerCallFromStatepointLoweringInfo(
340340
// to grab the return value from the return register(s), or it can be a LOAD
341341
// to load a value returned by reference via a stack slot.
342342

343+
if (CallEnd->getOpcode() == ISD::EH_LABEL)
344+
CallEnd = CallEnd->getOperand(0).getNode();
345+
343346
bool HasDef = !SI.CLI.RetTy->isVoidTy();
344347
if (HasDef) {
345348
if (CallEnd->getOpcode() == ISD::LOAD)
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
; RUN: llc %s -filetype=obj -o - | llvm-readobj -r - | FileCheck %s --check-prefix=RELOC
2+
; RUN: llc %s -o - | FileCheck %s --check-prefix=ASM
3+
4+
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
5+
target triple = "x86_64-apple-macosx"
6+
7+
define swiftcc void @rdar113994760() personality ptr @__gcc_personality_v0 {
8+
entry:
9+
%swifterror = alloca swifterror ptr, align 8
10+
invoke swiftcc void null(i64 0, ptr null, ptr swifterror %swifterror)
11+
to label %.noexc unwind label %tsan_cleanup
12+
13+
.noexc: ; preds = %entry
14+
ret void
15+
16+
tsan_cleanup: ; preds = %entry
17+
%cleanup.lpad = landingpad { ptr, i32 }
18+
cleanup
19+
resume { ptr, i32 } zeroinitializer
20+
}
21+
22+
declare i32 @__gcc_personality_v0(...)
23+
24+
; RELOC-LABEL: Relocations [
25+
; RELOC-NEXT: Section __text {
26+
; RELOC-NEXT: 0x18 1 2 1 X86_64_RELOC_BRANCH 0 __Unwind_Resume
27+
; RELOC-NEXT: }
28+
; RELOC-NEXT: Section __eh_frame {
29+
; RELOC-NEXT: 0x13 1 2 1 X86_64_RELOC_GOT 0 ___gcc_personality_v0
30+
; RELOC-NEXT: }
31+
; RELOC-NEXT: ]
32+
33+
; ASM-LABEL: rdar113994760:
34+
; ASM: ## %bb.0: ## %entry
35+
; ASM-NEXT: pushq %r12
36+
; ASM-NEXT: .cfi_def_cfa_offset 16
37+
; ASM-NEXT: subq $16, %rsp
38+
; ASM-NEXT: .cfi_def_cfa_offset 32
39+
; ASM-NEXT: .cfi_offset %r12, -16
40+
; ASM-NEXT: Ltmp0:
41+
; ASM-NEXT: xorl %eax, %eax
42+
; ASM-NEXT: xorl %edi, %edi
43+
; ASM-NEXT: xorl %esi, %esi
44+
; ASM-NEXT: callq *%rax
45+
; ASM-NEXT: Ltmp1:
46+
; ASM-NEXT: ## %bb.1: ## %.noexc
47+
; ASM-NEXT: addq $16, %rsp
48+
; ASM-NEXT: popq %r12
49+
; ASM-NEXT: retq
50+
; ASM-NEXT: LBB0_2: ## %tsan_cleanup
51+
; ASM-NEXT: Ltmp2:
52+
; ASM-NEXT: xorl %edi, %edi
53+
; ASM-NEXT: callq __Unwind_Resume
54+
; ASM-NEXT: Lfunc_end0:
55+
; ASM-NEXT: .cfi_endproc
56+
; ASM-NEXT: .section __TEXT,__gcc_except_tab
57+
; ASM-NEXT: .p2align 2, 0x0
58+
; ASM-NEXT: GCC_except_table0:
59+
; ASM-NEXT: Lexception0:
60+
; ASM-NEXT: .byte 255 ## @LPStart Encoding = omit
61+
; ASM-NEXT: .byte 255 ## @TType Encoding = omit
62+
; ASM-NEXT: .byte 1 ## Call site Encoding = uleb128
63+
; ASM-NEXT: .uleb128 Lcst_end0-Lcst_begin0
64+
; ASM-NEXT: Lcst_begin0:
65+
; ASM-NEXT: .uleb128 Ltmp0-Lfunc_begin0 ## >> Call Site 1 <<
66+
; ASM-NEXT: .uleb128 Ltmp1-Ltmp0 ## Call between Ltmp0 and Ltmp1
67+
; ASM-NEXT: .uleb128 Ltmp2-Lfunc_begin0 ## jumps to Ltmp2
68+
; ASM-NEXT: .byte 0 ## On action: cleanup
69+
; ASM-NEXT: .uleb128 Ltmp1-Lfunc_begin0 ## >> Call Site 2 <<
70+
; ASM-NEXT: .uleb128 Lfunc_end0-Ltmp1 ## Call between Ltmp1 and Lfunc_end0
71+
; ASM-NEXT: .byte 0 ## has no landing pad
72+
; ASM-NEXT: .byte 0 ## On action: cleanup
73+
; ASM-NEXT: Lcst_end0:
74+
; ASM-NEXT: .p2align 2, 0x0
75+
; ASM-NEXT: ## -- End function

0 commit comments

Comments
 (0)