Page MenuHomePhabricator

Emit a trap instruction for IR 'unreachable'
ClosedPublic

Authored by yaron.keren on Apr 18 2014, 12:28 AM.

Details

Summary

Patch by Vadim Chugunov.

I made a patch that fixes the "missing epilogue" problem by emitting a trap instruction for IR 'unreachable'.
A secondary use for it would be for anyone wanting to make double-sure that 'noreturn' functions, indeed, do not return.

Diff Detail

Event Timeline

Looks like this is missing my changes to include/llvm/Target/TargetOptions.h

yaron.keren updated this revision to Unknown Object (????).Apr 18 2014, 1:50 AM

Ok, not sure why the TargetOptions.h patch didn't go in, but here it is.

rnk accepted this revision.Apr 18 2014, 1:05 PM

LGTM

The patch isn't displaying correctly, but the combination of the diffs looks good. A good followup would be to wire this through Clang's CodeGenOptions.

yaron.keren updated this revision to Unknown Object (????).Apr 18 2014, 1:29 PM

I didn't use Phabricator correctly, hence the diff was split into two parts.
Here is the complete diff, the combination of the preceding two.

asl accepted this revision.Apr 18 2014, 11:44 PM

LGTM

yaron.keren updated this revision to Unknown Object (????).Apr 18 2014, 11:48 PM

With test.

asl added inline comments.Apr 18 2014, 11:51 PM
test/CodeGen/X86/br-fold.ll
4

The test should include the explicit target triple then, right?

I would at least write it as:

; CHECK-NEXT: ud2
; CHECK-NEXT: %bb8.i329

to preserve the original intent of the test as well.

Also, I would expect to see ud2 only on x64 windows, not for other x64 OS'es. Hmm... Perhaps it would be better to change this test to use non-Windows target triple, and write another one that specifically checks 'unreachable' -> 'ud2' transform on x64 Windows?

yaron.keren updated this revision to Unknown Object (????).Apr 19 2014, 12:38 AM

Updated for x64 : linux, windows, windows-gnu

Anton & Vadim, test now three triples.

Vadim, there is no label on Windows after the patch, the output is for x64_86-pc-windows is:

.text
.def     foo;
.scl    2;
.type   32;
.endef
.globl  foo
.align  16, 0x90

foo: # @foo

BB#0: # %entry

leaq    _ZN11xercesc_2_56XMLUni16fgNotationStringE(%rip), %rax
leaq    _ZN11xercesc_2_513SchemaSymbols21fgURI_SCHEMAFORSCHEMAE(%rip), %rcx
orq     %rax, %rcx
ud2

should the label still be there?

code was cut off, trying again:

`foo: # @foo

BB#0: # %entry

leaq    _ZN11xercesc_2_56XMLUni16fgNotationStringE(%rip), %rax
leaq    _ZN11xercesc_2_513SchemaSymbols21fgURI_SCHEMAFORSCHEMAE(%rip), %rcx
orq     %rax, %rcx
ud2

`

foo:                                    # @foo
# BB#0:                                 # %entry
        leaq    _ZN11xercesc_2_56XMLUni16fgNotationStringE(%rip), %rax
        leaq    _ZN11xercesc_2_513SchemaSymbols21fgURI_SCHEMAFORSCHEMAE(%rip), %rcx
        orq     %rax, %rcx
        ud2

ok, this time looks good. Anyhow, ud2 is the last instruction.

yaron.keren closed this revision.Apr 19 2014, 6:55 AM

Added a test for x86_64-apple-darwin and committed in r206684.

Thanks for seeing this through!