diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2024-04-12 20:02:22 -0700 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2024-05-08 20:36:11 -0700 |
| commit | 443bdc0946a418943c4fd23aedee0c6b4fa00294 (patch) | |
| tree | 3e533c5e605abee3d85dbbd4b7871896461e5d4f /tests/codegen | |
| parent | 87293c9585a7fb2cc83ca9949ae79661d5d3c31a (diff) | |
| download | rust-443bdc0946a418943c4fd23aedee0c6b4fa00294.tar.gz rust-443bdc0946a418943c4fd23aedee0c6b4fa00294.zip | |
Add a codegen test for transparent aggregates
Diffstat (limited to 'tests/codegen')
| -rw-r--r-- | tests/codegen/mir-aggregate-no-alloca.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/codegen/mir-aggregate-no-alloca.rs b/tests/codegen/mir-aggregate-no-alloca.rs new file mode 100644 index 00000000000..8714fc56980 --- /dev/null +++ b/tests/codegen/mir-aggregate-no-alloca.rs @@ -0,0 +1,39 @@ +//@ compile-flags: -O -C no-prepopulate-passes + +#![crate_type = "lib"] + +#[repr(transparent)] +struct Transparent32(u32); + +// CHECK: i32 @make_transparent(i32 noundef %x) +#[no_mangle] +pub fn make_transparent(x: u32) -> Transparent32 { + // CHECK: %a = alloca i32 + // CHECK: store i32 %x, ptr %a + // CHECK: %[[TEMP:.+]] = load i32, ptr %a + // CHECK: ret i32 %[[TEMP]] + let a = Transparent32(x); + a +} + +// CHECK: i32 @make_closure(i32 noundef %x) +#[no_mangle] +pub fn make_closure(x: i32) -> impl Fn(i32) -> i32 { + // CHECK: %[[ALLOCA:.+]] = alloca i32 + // CHECK: store i32 %x, ptr %[[ALLOCA]] + // CHECK: %[[TEMP:.+]] = load i32, ptr %[[ALLOCA]] + // CHECK: ret i32 %[[TEMP]] + move |y| x + y +} + +// CHECK-LABEL: { i32, i32 } @make_2_tuple(i32 noundef %x) +#[no_mangle] +pub fn make_2_tuple(x: u32) -> (u32, u32) { + // CHECK: %pair = alloca { i32, i32 } + // CHECK: store i32 + // CHECK: store i32 + // CHECK: load i32 + // CHECK: load i32 + let pair = (x, x); + pair +} |
