[llvm] r330073 - MachO: trap unreachable instructions
Tim Northover via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 13 15:25:20 PDT 2018
Author: tnorthover
Date: Fri Apr 13 15:25:20 2018
New Revision: 330073
URL: http://llvm.org/viewvc/llvm-project?rev=330073&view=rev
Log:
MachO: trap unreachable instructions
Debugability is more important than saving 4 bytes to let us to fall
through to nonense.
Added:
llvm/trunk/test/CodeGen/AArch64/macho-trap.ll
llvm/trunk/test/CodeGen/ARM/macho-trap.ll
llvm/trunk/test/CodeGen/X86/macho-trap.ll
Modified:
llvm/trunk/lib/Target/AArch64/AArch64TargetMachine.cpp
llvm/trunk/lib/Target/ARM/ARMTargetMachine.cpp
llvm/trunk/lib/Target/X86/X86TargetMachine.cpp
llvm/trunk/test/CodeGen/ARM/fast-isel-shift-materialize.ll
llvm/trunk/test/CodeGen/Thumb2/thumb2-ifcvt2.ll
llvm/trunk/test/CodeGen/X86/avx512-fsel.ll
llvm/trunk/test/CodeGen/X86/br-fold.ll
llvm/trunk/test/CodeGen/X86/eh-frame-unreachable.ll
llvm/trunk/test/CodeGen/X86/empty-functions.ll
llvm/trunk/test/CodeGen/X86/pr34421.ll
llvm/trunk/test/MC/MachO/ARM/empty-function-nop.ll
Modified: llvm/trunk/lib/Target/AArch64/AArch64TargetMachine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64TargetMachine.cpp?rev=330073&r1=330072&r2=330073&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/AArch64TargetMachine.cpp (original)
+++ llvm/trunk/lib/Target/AArch64/AArch64TargetMachine.cpp Fri Apr 13 15:25:20 2018
@@ -244,6 +244,9 @@ AArch64TargetMachine::AArch64TargetMachi
TLOF(createTLOF(getTargetTriple())), isLittle(LittleEndian) {
initAsmInfo();
+ if (TT.isOSBinFormatMachO())
+ this->Options.TrapUnreachable = true;
+
// Enable GlobalISel at or below EnableGlobalISelAt0.
if (getOptLevel() <= EnableGlobalISelAtO)
setGlobalISel(true);
Modified: llvm/trunk/lib/Target/ARM/ARMTargetMachine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMTargetMachine.cpp?rev=330073&r1=330072&r2=330073&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMTargetMachine.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMTargetMachine.cpp Fri Apr 13 15:25:20 2018
@@ -238,6 +238,9 @@ ARMBaseTargetMachine::ARMBaseTargetMachi
this->Options.EABIVersion = EABI::EABI5;
}
+ if (TT.isOSBinFormatMachO())
+ this->Options.TrapUnreachable = true;
+
initAsmInfo();
}
Modified: llvm/trunk/lib/Target/X86/X86TargetMachine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86TargetMachine.cpp?rev=330073&r1=330072&r2=330073&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86TargetMachine.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86TargetMachine.cpp Fri Apr 13 15:25:20 2018
@@ -224,7 +224,8 @@ X86TargetMachine::X86TargetMachine(const
// The check here for 64-bit windows is a bit icky, but as we're unlikely
// to ever want to mix 32 and 64-bit windows code in a single module
// this should be fine.
- if ((TT.isOSWindows() && TT.getArch() == Triple::x86_64) || TT.isPS4())
+ if ((TT.isOSWindows() && TT.getArch() == Triple::x86_64) || TT.isPS4() ||
+ TT.isOSBinFormatMachO())
this->Options.TrapUnreachable = true;
initAsmInfo();
Added: llvm/trunk/test/CodeGen/AArch64/macho-trap.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/macho-trap.ll?rev=330073&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/macho-trap.ll (added)
+++ llvm/trunk/test/CodeGen/AArch64/macho-trap.ll Fri Apr 13 15:25:20 2018
@@ -0,0 +1,7 @@
+; RUN: llc -mtriple=aarch64-apple-ios7.0 %s -o - | FileCheck %s
+
+define void @test_unreachable() {
+; CHECK-LABEL: test_unreachable:
+; CHECK: brk #0x1
+ unreachable
+}
Modified: llvm/trunk/test/CodeGen/ARM/fast-isel-shift-materialize.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/fast-isel-shift-materialize.ll?rev=330073&r1=330072&r2=330073&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/ARM/fast-isel-shift-materialize.ll (original)
+++ llvm/trunk/test/CodeGen/ARM/fast-isel-shift-materialize.ll Fri Apr 13 15:25:20 2018
@@ -19,7 +19,7 @@ bb:
%tmp4 = lshr i32 %tmp3, 2
%tmp10 = lshr i32 %tmp9, 2
call void @foo(i32 %tmp10, i32 %tmp4)
- unreachable
+ ret i32 undef
}
attributes #0 = { minsize }
Added: llvm/trunk/test/CodeGen/ARM/macho-trap.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/macho-trap.ll?rev=330073&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/ARM/macho-trap.ll (added)
+++ llvm/trunk/test/CodeGen/ARM/macho-trap.ll Fri Apr 13 15:25:20 2018
@@ -0,0 +1,10 @@
+; RUN: llc -mtriple=armv7-apple-ios7.0 %s -o - | FileCheck %s
+; RUN: llc -mtriple=thumbv7-apple-ios7.0 %s -o - | FileCheck %s
+; RUN: llc -mtriple=thumbv7m-apple-macho %s -o - | FileCheck %s
+; RUN: llc -mtriple=thumbv6m-apple-macho %s -o - | FileCheck %s
+
+define void @test_unreachable() {
+; CHECK-LABEL: test_unreachable:
+; CHECK: trap
+ unreachable
+}
Modified: llvm/trunk/test/CodeGen/Thumb2/thumb2-ifcvt2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Thumb2/thumb2-ifcvt2.ll?rev=330073&r1=330072&r2=330073&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/Thumb2/thumb2-ifcvt2.ll (original)
+++ llvm/trunk/test/CodeGen/Thumb2/thumb2-ifcvt2.ll Fri Apr 13 15:25:20 2018
@@ -72,7 +72,7 @@ entry:
cond_true: ; preds = %entry
tail call void @abort( )
- unreachable
+ ret void
cond_false: ; preds = %entry
ret void
@@ -82,7 +82,7 @@ define fastcc void @t2() nounwind {
entry:
; CHECK-LABEL: t2:
; CHECK: cmp r0, #0
-; CHECK: %growMapping.exit
+; CHECK: trap
br i1 undef, label %bb.i.i3, label %growMapping.exit
bb.i.i3: ; preds = %entry
Modified: llvm/trunk/test/CodeGen/X86/avx512-fsel.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/avx512-fsel.ll?rev=330073&r1=330072&r2=330073&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/avx512-fsel.ll (original)
+++ llvm/trunk/test/CodeGen/X86/avx512-fsel.ll Fri Apr 13 15:25:20 2018
@@ -19,6 +19,7 @@ define i32 @test(float %a, float %b) {
; CHECK-NEXT: jmp LBB0_2
; CHECK-NEXT: LBB0_1: ## %L_0
; CHECK-NEXT: callq ___assert_rtn
+; CHECK-NEXT: ud2
; CHECK-NEXT: LBB0_2: ## %L_1
; CHECK-NEXT: xorl %eax, %eax
; CHECK-NEXT: popq %rcx
Modified: llvm/trunk/test/CodeGen/X86/br-fold.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/br-fold.ll?rev=330073&r1=330072&r2=330073&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/br-fold.ll (original)
+++ llvm/trunk/test/CodeGen/X86/br-fold.ll Fri Apr 13 15:25:20 2018
@@ -5,8 +5,7 @@
; RUN: llc -mtriple=x86_64-scei-ps4 < %s | FileCheck -check-prefix=PS4 %s
; X64_DARWIN: orq
-; X64_DARWIN-NEXT: jne
-; X64_DARWIN-NEXT: %bb8.i329
+; X64-DARWIN-NEXT: ud2
; X64_LINUX: orq %rax, %rcx
; X64_LINUX-NEXT: jne
Modified: llvm/trunk/test/CodeGen/X86/eh-frame-unreachable.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/eh-frame-unreachable.ll?rev=330073&r1=330072&r2=330073&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/eh-frame-unreachable.ll (original)
+++ llvm/trunk/test/CodeGen/X86/eh-frame-unreachable.ll Fri Apr 13 15:25:20 2018
@@ -2,6 +2,7 @@
; Test that we don't emit a row that extends beyond the FDE's range_size.
;
; CHECK: movq %rsp, %rbp
+; CHECK: ud2
; CHECK-NEXT: .cfi_endproc
; CHECK-NOT: .cfi
Modified: llvm/trunk/test/CodeGen/X86/empty-functions.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/empty-functions.ll?rev=330073&r1=330072&r2=330073&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/empty-functions.ll (original)
+++ llvm/trunk/test/CodeGen/X86/empty-functions.ll Fri Apr 13 15:25:20 2018
@@ -11,7 +11,7 @@ entry:
; MachO cannot handle an empty function.
; CHECK-NO-FP: _func:
; CHECK-NO-FP-NEXT: .cfi_startproc
-; CHECK-NO-FP: nop
+; CHECK-NO-FP: ud2
; CHECK-NO-FP-NEXT: .cfi_endproc
; CHECK-FP: _func:
@@ -21,7 +21,8 @@ entry:
; CHECK-FP-NEXT: .cfi_def_cfa_offset 16
; CHECK-FP-NEXT: .cfi_offset %rbp, -16
; CHECK-FP-NEXT: movq %rsp, %rbp
-; CHECK-FP-NEXT: .cfi_endproc
+; CHECK-FP: ud2
+; CHECK-FP: .cfi_endproc
; An empty function is perfectly fine on ELF.
; LINUX-NO-FP: func:
Added: llvm/trunk/test/CodeGen/X86/macho-trap.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/macho-trap.ll?rev=330073&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/macho-trap.ll (added)
+++ llvm/trunk/test/CodeGen/X86/macho-trap.ll Fri Apr 13 15:25:20 2018
@@ -0,0 +1,7 @@
+; RUN: llc -mtriple=x86_64-apple-macosx10.11 %s -o - | FileCheck %s
+
+define void @test_unreachable() {
+; CHECK-LABEL: test_unreachable:
+; CHECK: ud2
+ unreachable
+}
Modified: llvm/trunk/test/CodeGen/X86/pr34421.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/pr34421.ll?rev=330073&r1=330072&r2=330073&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/pr34421.ll (original)
+++ llvm/trunk/test/CodeGen/X86/pr34421.ll Fri Apr 13 15:25:20 2018
@@ -14,6 +14,7 @@ define void @thread_selfcounts() noimpli
; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
; X86-NEXT: movl %ecx, {{[0-9]+}}(%esp)
; X86-NEXT: movl %eax, {{[0-9]+}}(%esp)
+; X86-NEXT: ud2
; X86-NEXT: ## -- End function
;
; X64-LABEL: thread_selfcounts:
@@ -23,6 +24,7 @@ define void @thread_selfcounts() noimpli
; X64-NEXT: movq {{[0-9]+}}(%rsp), %rcx
; X64-NEXT: movq %rax, (%rsp)
; X64-NEXT: movq %rcx, {{[0-9]+}}(%rsp)
+; X64-NEXT: ud2
; X64-NEXT: ## -- End function
entry:
%counts = alloca [2 x i64], align 16
Modified: llvm/trunk/test/MC/MachO/ARM/empty-function-nop.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/MachO/ARM/empty-function-nop.ll?rev=330073&r1=330072&r2=330073&view=diff
==============================================================================
--- llvm/trunk/test/MC/MachO/ARM/empty-function-nop.ll (original)
+++ llvm/trunk/test/MC/MachO/ARM/empty-function-nop.ll Fri Apr 13 15:25:20 2018
@@ -10,14 +10,14 @@ define internal fastcc void @empty_funct
unreachable
}
; CHECK-T1: SectionData (
-; CHECK-T1: 0000: C046 |.F|
+; CHECK-T1: 0000: FEDE |..|
; CHECK-T1: )
; CHECK-T2: SectionData (
-; CHECK-T2: 0000: 00BF |..|
+; CHECK-T2: 0000: FEDE |..|
; CHECK-T2: )
; CHECK-ARM: SectionData (
-; CHECK-ARM: 0000: 0000A0E1 |....|
+; CHECK-ARM: 0000: FEDEFFE7 |....|
; CHECK-ARM: )
; CHECK-ARMV7: SectionData (
-; CHECK-ARMV7: 0000: 00F020E3 |.. .|
+; CHECK-ARMV7: 0000: FEDEFFE7 |....|
; CHECK-ARMV7: )
More information about the llvm-commits
mailing list