Skip to content

Dead code elimination fails when panicking in drop impl and panicable function is called #114532

Open
@SUPERCILEX

Description

@SUPERCILEX
struct Foo(bool);

impl Drop for Foo {
    fn drop(&mut self) {
        if self.0 {
            return;
        }

        panic!("dead");
    }
}

pub fn foo() {
    let a = Foo(true);
    unsafe {unknown(9);}
}

extern "Rust" {
    fn unknown(x: i32) -> bool;
}

https://rust.godbolt.org/z/zzoee9z1W

Removing either the drop panic or the unknown call enables full optimizations, the but their combination does not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-codegenArea: Code generationC-bugCategory: This is a bug.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