Skip to content

Commit 6fc1d8b

Browse files
add codegen test
1 parent 68217c9 commit 6fc1d8b

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/test/codegen/zst-offset.rs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// compile-flags: -C no-prepopulate-passes
2+
3+
#![crate_type = "lib"]
4+
5+
// Hack to get the correct size for the length part in slices
6+
// CHECK: @helper([[USIZE:i[0-9]+]] %_1)
7+
#[no_mangle]
8+
pub fn helper(_: usize) {
9+
}
10+
11+
// Check that we correctly generate a GEP for a ZST that is not included in Scalar layout
12+
// CHECK-LABEL: @scalar_layout
13+
#[no_mangle]
14+
pub fn scalar_layout(s: &(u64, ())) {
15+
// CHECK: [[X0:%[0-9]+]] = bitcast i64* %s to i8*
16+
// CHECK-NEXT: [[X1:%[0-9]+]] = getelementptr i8, i8* [[X0]], [[USIZE]] 8
17+
let x = &s.1;
18+
&x; // keep variable in an alloca
19+
}
20+
21+
// Check that we correctly generate a GEP for a ZST that is not included in ScalarPair layout
22+
// CHECK-LABEL: @scalarpair_layout
23+
#[no_mangle]
24+
pub fn scalarpair_layout(s: &(u64, u32, ())) {
25+
// CHECK: [[X0:%[0-9]+]] = bitcast { i64, i32 }* %s to i8*
26+
// CHECK-NEXT: [[X1:%[0-9]+]] = getelementptr i8, i8* [[X0]], [[USIZE]] 12
27+
let x = &s.2;
28+
&x; // keep variable in an alloca
29+
}

0 commit comments

Comments
 (0)