Skip to content

Commit 617af3c

Browse files
authored
AArch64: Base MCAsmInfo type on binary format before OS (#147875)
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 378e9bb commit 617af3c

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-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: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
4+
; Make sure windows elf does not assert with exceptions. This is a
5+
; hack for MCJIT that could be treated as an error when it is removed.
6+
7+
@_ZTIi = external global ptr
8+
9+
declare i32 @foo(i32)
10+
declare i32 @__gxx_personality_v0(...)
11+
12+
define void @bar() personality ptr @__gxx_personality_v0 {
13+
; CHECK-LABEL: bar:
14+
; CHECK: // %bb.0: // %continue
15+
; CHECK-NEXT: sub sp, sp, #32
16+
; CHECK-NEXT: str x30, [sp, #16] // 8-byte Folded Spill
17+
; CHECK-NEXT: .cfi_def_cfa_offset 32
18+
; CHECK-NEXT: .cfi_offset w30, -16
19+
; CHECK-NEXT: adrp x8, :got:foo
20+
; CHECK-NEXT: mov w0, #42 // =0x2a
21+
; CHECK-NEXT: ldr x8, [x8, :got_lo12:foo]
22+
; CHECK-NEXT: blr x8
23+
; CHECK-NEXT: ldr x30, [sp, #16] // 8-byte Folded Reload
24+
; CHECK-NEXT: add sp, sp, #32
25+
; CHECK-NEXT: ret
26+
%exn.slot = alloca ptr
27+
%ehselector.slot = alloca i32
28+
%1 = invoke i32 @foo(i32 42) to label %continue unwind label %cleanup
29+
30+
cleanup:
31+
%lp = landingpad { ptr, i32 } cleanup
32+
%lp.0 = extractvalue { ptr, i32 } %lp, 0
33+
store ptr %lp.0, ptr %exn.slot, align 8
34+
%lp.1 = extractvalue { ptr, i32 } %lp, 1
35+
store i32 %lp.1, ptr %ehselector.slot, align 4
36+
br label %eh.resume
37+
38+
continue:
39+
ret void
40+
41+
eh.resume:
42+
%exn = load ptr, ptr %exn.slot, align 8
43+
unreachable
44+
}

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)