Skip to content

Commit 3352f51

Browse files
committed
MachO: trap unreachable instructions
Debugability is more important than saving 4 bytes to let us to fall through to nonense. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330073 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent a68402c commit 3352f51

14 files changed

+47
-12
lines changed

lib/Target/AArch64/AArch64TargetMachine.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ AArch64TargetMachine::AArch64TargetMachine(const Target &T, const Triple &TT,
244244
TLOF(createTLOF(getTargetTriple())), isLittle(LittleEndian) {
245245
initAsmInfo();
246246

247+
if (TT.isOSBinFormatMachO())
248+
this->Options.TrapUnreachable = true;
249+
247250
// Enable GlobalISel at or below EnableGlobalISelAt0.
248251
if (getOptLevel() <= EnableGlobalISelAtO)
249252
setGlobalISel(true);

lib/Target/ARM/ARMTargetMachine.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,9 @@ ARMBaseTargetMachine::ARMBaseTargetMachine(const Target &T, const Triple &TT,
238238
this->Options.EABIVersion = EABI::EABI5;
239239
}
240240

241+
if (TT.isOSBinFormatMachO())
242+
this->Options.TrapUnreachable = true;
243+
241244
initAsmInfo();
242245
}
243246

lib/Target/X86/X86TargetMachine.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ X86TargetMachine::X86TargetMachine(const Target &T, const Triple &TT,
224224
// The check here for 64-bit windows is a bit icky, but as we're unlikely
225225
// to ever want to mix 32 and 64-bit windows code in a single module
226226
// this should be fine.
227-
if ((TT.isOSWindows() && TT.getArch() == Triple::x86_64) || TT.isPS4())
227+
if ((TT.isOSWindows() && TT.getArch() == Triple::x86_64) || TT.isPS4() ||
228+
TT.isOSBinFormatMachO())
228229
this->Options.TrapUnreachable = true;
229230

230231
initAsmInfo();

test/CodeGen/AArch64/macho-trap.ll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
; RUN: llc -mtriple=aarch64-apple-ios7.0 %s -o - | FileCheck %s
2+
3+
define void @test_unreachable() {
4+
; CHECK-LABEL: test_unreachable:
5+
; CHECK: brk #0x1
6+
unreachable
7+
}

test/CodeGen/ARM/fast-isel-shift-materialize.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ bb:
1919
%tmp4 = lshr i32 %tmp3, 2
2020
%tmp10 = lshr i32 %tmp9, 2
2121
call void @foo(i32 %tmp10, i32 %tmp4)
22-
unreachable
22+
ret i32 undef
2323
}
2424

2525
attributes #0 = { minsize }

test/CodeGen/ARM/macho-trap.ll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
; RUN: llc -mtriple=armv7-apple-ios7.0 %s -o - | FileCheck %s
2+
; RUN: llc -mtriple=thumbv7-apple-ios7.0 %s -o - | FileCheck %s
3+
; RUN: llc -mtriple=thumbv7m-apple-macho %s -o - | FileCheck %s
4+
; RUN: llc -mtriple=thumbv6m-apple-macho %s -o - | FileCheck %s
5+
6+
define void @test_unreachable() {
7+
; CHECK-LABEL: test_unreachable:
8+
; CHECK: trap
9+
unreachable
10+
}

test/CodeGen/Thumb2/thumb2-ifcvt2.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ entry:
7272

7373
cond_true: ; preds = %entry
7474
tail call void @abort( )
75-
unreachable
75+
ret void
7676

7777
cond_false: ; preds = %entry
7878
ret void
@@ -82,7 +82,7 @@ define fastcc void @t2() nounwind {
8282
entry:
8383
; CHECK-LABEL: t2:
8484
; CHECK: cmp r0, #0
85-
; CHECK: %growMapping.exit
85+
; CHECK: trap
8686
br i1 undef, label %bb.i.i3, label %growMapping.exit
8787

8888
bb.i.i3: ; preds = %entry

test/CodeGen/X86/avx512-fsel.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ define i32 @test(float %a, float %b) {
1919
; CHECK-NEXT: jmp LBB0_2
2020
; CHECK-NEXT: LBB0_1: ## %L_0
2121
; CHECK-NEXT: callq ___assert_rtn
22+
; CHECK-NEXT: ud2
2223
; CHECK-NEXT: LBB0_2: ## %L_1
2324
; CHECK-NEXT: xorl %eax, %eax
2425
; CHECK-NEXT: popq %rcx

test/CodeGen/X86/br-fold.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
; RUN: llc -mtriple=x86_64-scei-ps4 < %s | FileCheck -check-prefix=PS4 %s
66

77
; X64_DARWIN: orq
8-
; X64_DARWIN-NEXT: jne
9-
; X64_DARWIN-NEXT: %bb8.i329
8+
; X64-DARWIN-NEXT: ud2
109

1110
; X64_LINUX: orq %rax, %rcx
1211
; X64_LINUX-NEXT: jne

test/CodeGen/X86/eh-frame-unreachable.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
; Test that we don't emit a row that extends beyond the FDE's range_size.
33
;
44
; CHECK: movq %rsp, %rbp
5+
; CHECK: ud2
56
; CHECK-NEXT: .cfi_endproc
67
; CHECK-NOT: .cfi
78

0 commit comments

Comments
 (0)