From f849721dbd3afaa10b9aacb2e5528b0197a44720 Mon Sep 17 00:00:00 2001 From: Amirhossein Akhlaghpour Date: Fri, 17 Jul 2026 18:08:12 +0330 Subject: [PATCH] chore: add codegen test for enum clone Signed-off-by: Amirhossein Akhlaghpour --- tests/codegen-llvm/issues/issue-69174.rs | 35 ++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/codegen-llvm/issues/issue-69174.rs diff --git a/tests/codegen-llvm/issues/issue-69174.rs b/tests/codegen-llvm/issues/issue-69174.rs new file mode 100644 index 0000000000000..411c5a8e89c76 --- /dev/null +++ b/tests/codegen-llvm/issues/issue-69174.rs @@ -0,0 +1,35 @@ +// Cloning small nested enums should not require branching code. + +//@ compile-flags: -Copt-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_foo +// CHECK-NOT: br i1 +// CHECK-NOT: switch +// CHECK: ret +#[no_mangle] +pub fn clone_foo(f: &Foo) -> Foo { + f.clone() +} + +// CHECK-LABEL: @clone_bar +// CHECK-NOT: br i1 +// CHECK-NOT: switch +// CHECK: ret +#[no_mangle] +pub fn clone_bar(b: &Bar) -> Bar { + b.clone() +}