Skip to content

Commit 7be95d4

Browse files
committed
AArch64: Base exception type on binary format before OS
Fixes asserting with windows-elf triples. Should fix regression reported in #147225 (comment) I'm not sure this is a valid triple, but I'm guessing the MCJIT usage is an accident. This does change the behavior from trying to use WinEH to DwarfCFI; however the backend crashes with WinEH so I'm assuming following ELF is the more correct option.
1 parent 0b49f2f commit 7be95d4

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
lines changed

llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,14 +349,14 @@ static MCAsmInfo *createAArch64MCAsmInfo(const MCRegisterInfo &MRI,
349349
MCAsmInfo *MAI;
350350
if (TheTriple.isOSBinFormatMachO())
351351
MAI = new AArch64MCAsmInfoDarwin(TheTriple.getArch() == Triple::aarch64_32);
352+
else if (TheTriple.isOSBinFormatELF())
353+
MAI = new AArch64MCAsmInfoELF(TheTriple);
352354
else if (TheTriple.isWindowsMSVCEnvironment())
353355
MAI = new AArch64MCAsmInfoMicrosoftCOFF();
354356
else if (TheTriple.isOSBinFormatCOFF())
355357
MAI = new AArch64MCAsmInfoGNUCOFF();
356-
else {
357-
assert(TheTriple.isOSBinFormatELF() && "Invalid target");
358-
MAI = new AArch64MCAsmInfoELF(TheTriple);
359-
}
358+
else
359+
llvm_unreachable("Invalid target"); // FIXME: This is not unreachable
360360

361361
// Initial state of the frame pointer is SP.
362362
unsigned Reg = MRI.getDwarfRegNum(AArch64::SP, true);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -mtriple=aarch64-pc-windows-elf < %s | FileCheck %s
3+
; Make sure windows elf does not assert with exceptions
4+
5+
@_ZTIi = external global ptr
6+
7+
declare i32 @foo(i32)
8+
declare i32 @__gxx_personality_v0(...)
9+
10+
define void @bar() personality ptr @__gxx_personality_v0 {
11+
; CHECK-LABEL: bar:
12+
; CHECK: // %bb.0: // %continue
13+
; CHECK-NEXT: sub sp, sp, #32
14+
; CHECK-NEXT: str x30, [sp, #16] // 8-byte Folded Spill
15+
; CHECK-NEXT: .cfi_def_cfa_offset 32
16+
; CHECK-NEXT: .cfi_offset w30, -16
17+
; CHECK-NEXT: adrp x8, :got:foo
18+
; CHECK-NEXT: mov w0, #42 // =0x2a
19+
; CHECK-NEXT: ldr x8, [x8, :got_lo12:foo]
20+
; CHECK-NEXT: blr x8
21+
; CHECK-NEXT: ldr x30, [sp, #16] // 8-byte Folded Reload
22+
; CHECK-NEXT: add sp, sp, #32
23+
; CHECK-NEXT: ret
24+
%exn.slot = alloca ptr
25+
%ehselector.slot = alloca i32
26+
%1 = invoke i32 @foo(i32 42) to label %continue unwind label %cleanup
27+
28+
cleanup:
29+
%lp = landingpad { ptr, i32 } cleanup
30+
%lp.0 = extractvalue { ptr, i32 } %lp, 0
31+
store ptr %lp.0, ptr %exn.slot, align 8
32+
%lp.1 = extractvalue { ptr, i32 } %lp, 1
33+
store i32 %lp.1, ptr %ehselector.slot, align 4
34+
br label %eh.resume
35+
36+
continue:
37+
ret void
38+
39+
eh.resume:
40+
%exn = load ptr, ptr %exn.slot, align 8
41+
unreachable
42+
}

llvm/unittests/TargetParser/TripleTest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2909,6 +2909,10 @@ TEST(TripleTest, DefaultExceptionHandling) {
29092909

29102910
EXPECT_EQ(ExceptionHandling::DwarfCFI,
29112911
Triple("x86_64-scei-ps4").getDefaultExceptionHandling());
2912+
EXPECT_EQ(ExceptionHandling::WinEH,
2913+
Triple("aarch64-pc-windows-msvc").getDefaultExceptionHandling());
2914+
EXPECT_EQ(ExceptionHandling::DwarfCFI,
2915+
Triple("aarch64-pc-windows-elf").getDefaultExceptionHandling());
29122916
}
29132917

29142918
TEST(TripleTest, NormalizeWindows) {

0 commit comments

Comments
 (0)