Skip to content

Unneeded call to panic!() #73031

Description

@jrmuizel

The following:

pub enum All {
    None,
    Foo,
    Bar,
}

pub fn f(a: &mut All, q: i32) -> i32 {
    *a = if (q == 5) {
        All::Foo
    } else {
        All::Bar
    };
    match *a {
        All::None => unreachable!(),
        All::Foo => 1,
        All::Bar => 2,
    }
}

compiles to:

example::f:
        cmp     esi, 5
        sete    al
        mov     cl, 2
        sub     cl, al
        mov     byte ptr [rdi], cl
        mov     eax, 1
        cmp     cl, 1
        je      .LBB6_3
        cmp     cl, 2
        jne     .LBB6_4
        mov     eax, 2
.LBB6_3:
        ret
.LBB6_4:
        push    rax
        call    std::panicking::begin_panic
        ud2

The unreachable! and should be eliminated

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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.I-slowIssue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions