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