Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SUPERCILEX opened this issue Aug 6, 2023 · 2 comments
Labels
A-codegen Area: Code generation A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. I-slow Issue: Problems and improvements with respect to performance of generated code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@SUPERCILEX
Copy link
Contributor

SUPERCILEX commented Aug 6, 2023

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.

@SUPERCILEX SUPERCILEX added the C-bug Category: This is a bug. label Aug 6, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 6, 2023
@SUPERCILEX
Copy link
Contributor Author

SUPERCILEX commented Aug 6, 2023

Related harder issue: #114533

@nikic
Copy link
Contributor

nikic commented Aug 8, 2023

Pretty sure this is a duplicate of #87055.

@fmease fmease added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. I-slow Issue: Problems and improvements with respect to performance of generated code. A-codegen Area: Code generation T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Sep 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. I-slow Issue: Problems and improvements with respect to performance of generated code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants