Skip to content

Regression test for bad codegen of #[derive(Clone)] on enums #144961

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions tests/codegen-llvm/derive-clone-enum-variants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//! Regression test for bad codegen of `#[derive(Clone)]` on enums.
//! Ensures efficient LLVM IR without unnecessary branches.
//! See <https://github.com/rust-lang/rust/issues/69174>.

//@ compile-flags: -C opt-level=3

#![crate_type = "lib"]

#[derive(Clone)]
pub enum Foo {
A(u8),
B(bool),
}

#[derive(Clone)]
pub enum Bar {
C(Foo),
D(u8),
}

// CHECK-LABEL: @clone_bar
// CHECK-NOT: icmp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you adjust this to specifically check this is just a load + ret? That should be fairly future proof and avoids any regressions if this is something that's more complex but not an icmp.

  %0 = load i16, ptr %b, align 1
  ret i16 %0

#[unsafe(no_mangle)]
pub fn clone_bar(b: &Bar) -> Bar {
b.clone()
}
Loading