]> git.proxmox.com Git - rustc.git/blob - src/test/codegen/consts.rs
New upstream version 1.44.1+dfsg1
[rustc.git] / src / test / codegen / consts.rs
1 // compile-flags: -C no-prepopulate-passes
2 // ignore-tidy-linelength
3
4 #![crate_type = "lib"]
5
6 // Below, these constants are defined as enum variants that by itself would
7 // have a lower alignment than the enum type. Ensure that we mark them
8 // correctly with the higher alignment of the enum.
9
10 // CHECK: @STATIC = {{.*}}, align 4
11
12 // This checks the constants from inline_enum_const
13 // CHECK: @alloc5 = {{.*}}, align 2
14
15 // This checks the constants from {low,high}_align_const, they share the same
16 // constant, but the alignment differs, so the higher one should be used
17 // CHECK: [[LOW_HIGH:@[0-9]+]] = {{.*}} getelementptr inbounds (<{ [8 x i8] }>, <{ [8 x i8] }>* @alloc15, i32 0, i32 0, i32 0), {{.*}}
18
19 #[derive(Copy, Clone)]
20 // repr(i16) is required for the {low,high}_align_const test
21 #[repr(i16)]
22 pub enum E<A, B> {
23 A(A),
24 B(B),
25 }
26
27 #[no_mangle]
28 pub static STATIC: E<i16, i32> = E::A(0);
29
30 // CHECK-LABEL: @static_enum_const
31 #[no_mangle]
32 pub fn static_enum_const() -> E<i16, i32> {
33 STATIC
34 }
35
36 // CHECK-LABEL: @inline_enum_const
37 #[no_mangle]
38 pub fn inline_enum_const() -> E<i8, i16> {
39 *&E::A(0)
40 }
41
42 // CHECK-LABEL: @low_align_const
43 #[no_mangle]
44 pub fn low_align_const() -> E<i16, [i16; 3]> {
45 // Check that low_align_const and high_align_const use the same constant
46 // CHECK: load %"E<i16, [i16; 3]>"*, %"E<i16, [i16; 3]>"** bitcast (<{ i8*, [0 x i8] }>* [[LOW_HIGH]] to %"E<i16, [i16; 3]>"**),
47 *&E::A(0)
48 }
49
50 // CHECK-LABEL: @high_align_const
51 #[no_mangle]
52 pub fn high_align_const() -> E<i16, i32> {
53 // Check that low_align_const and high_align_const use the same constant
54 // CHECK: load %"E<i16, i32>"*, %"E<i16, i32>"** bitcast (<{ i8*, [0 x i8] }>* [[LOW_HIGH]] to %"E<i16, i32>"**),
55 *&E::A(0)
56 }