Skip to content

Infinite loop optimized out by inlining? #42009

Closed
@zackw

Description

@zackw

This crate

fn noret() -> ! { loop { } }
pub fn test_noret() -> () { noret() }

when compiled without optimization (rustc --crate-type rlib --emit asm), produces

_ZN4test5noret17hecd4eea31d87a48aE:
        .cfi_startproc
        jmp     .LBB0_1
.LBB0_1:
        jmp     .LBB0_1
.Lfunc_end0:
        .size   _ZN4test5noret17hecd4eea31d87a48aE, .Lfunc_end0-_ZN4test5noret17hecd4eea31d87a48aE
        .cfi_endproc
_ZN4test10test_noret17h492e3702bacafd6bE:
        .cfi_startproc
        pushq   %rax
.Lcfi0:
        .cfi_def_cfa_offset 16
        callq   _ZN4test5noret17hecd4eea31d87a48aE
.Lfunc_end1:
        .size   _ZN4test10test_noret17h492e3702bacafd6bE, .Lfunc_end1-_ZN4test10test_noret17h492e3702bacafd6bE
        .cfi_endproc

but when compiled with optimization on (rustc --crate-type rlib --emit asm -O), no assembly instructions at all are emitted for test_noret:

_ZN4test10test_noret17h492e3702bacafd6bE:
        .cfi_startproc
.Lfunc_end0:
        .size   _ZN4test10test_noret17h492e3702bacafd6bE, .Lfunc_end0-_ZN4test10test_noret17h492e3702bacafd6bE
        .cfi_endproc

I expected to get something like

_ZN4test10test_noret17h492e3702bacafd6bE:
        .cfi_startproc
.LBB0_1:
        jmp     .LBB0_1
.Lfunc_end0:
        .size   _ZN4test10test_noret17h492e3702bacafd6bE, .Lfunc_end0-_ZN4test10test_noret17h492e3702bacafd6bE
        .cfi_endproc

Identical behavior observed with rustc 1.17.0 (56124baa9 2017-04-24) and rustc 1.19.0-nightly (386b0b9d3 2017-05-14).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions