Skip to content

Commit 443bdc0

Browse files
committed
Add a codegen test for transparent aggregates
1 parent 87293c9 commit 443bdc0

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Diff for: tests/codegen/mir-aggregate-no-alloca.rs

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//@ compile-flags: -O -C no-prepopulate-passes
2+
3+
#![crate_type = "lib"]
4+
5+
#[repr(transparent)]
6+
struct Transparent32(u32);
7+
8+
// CHECK: i32 @make_transparent(i32 noundef %x)
9+
#[no_mangle]
10+
pub fn make_transparent(x: u32) -> Transparent32 {
11+
// CHECK: %a = alloca i32
12+
// CHECK: store i32 %x, ptr %a
13+
// CHECK: %[[TEMP:.+]] = load i32, ptr %a
14+
// CHECK: ret i32 %[[TEMP]]
15+
let a = Transparent32(x);
16+
a
17+
}
18+
19+
// CHECK: i32 @make_closure(i32 noundef %x)
20+
#[no_mangle]
21+
pub fn make_closure(x: i32) -> impl Fn(i32) -> i32 {
22+
// CHECK: %[[ALLOCA:.+]] = alloca i32
23+
// CHECK: store i32 %x, ptr %[[ALLOCA]]
24+
// CHECK: %[[TEMP:.+]] = load i32, ptr %[[ALLOCA]]
25+
// CHECK: ret i32 %[[TEMP]]
26+
move |y| x + y
27+
}
28+
29+
// CHECK-LABEL: { i32, i32 } @make_2_tuple(i32 noundef %x)
30+
#[no_mangle]
31+
pub fn make_2_tuple(x: u32) -> (u32, u32) {
32+
// CHECK: %pair = alloca { i32, i32 }
33+
// CHECK: store i32
34+
// CHECK: store i32
35+
// CHECK: load i32
36+
// CHECK: load i32
37+
let pair = (x, x);
38+
pair
39+
}

0 commit comments

Comments
 (0)