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