]> git.lizzy.rs Git - rust.git/blob - src/test/codegen/consts.rs
Update bool-cmp.rs codegen
[rust.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: @{{[0-9]+}} = {{.*}}, 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]+]] = {{.*}}, align 4
18
19 #[derive(Copy, Clone)]
20
21 // repr(i16) is required for the {low,high}_align_const test
22 #[repr(i16)]
23 pub enum E<A, B> {
24     A(A),
25     B(B),
26 }
27
28 #[no_mangle]
29 pub static STATIC: E<i16, i32> = E::A(0);
30
31 // CHECK-LABEL: @static_enum_const
32 #[no_mangle]
33 pub fn static_enum_const() -> E<i16, i32> {
34    STATIC
35 }
36
37 // CHECK-LABEL: @inline_enum_const
38 #[no_mangle]
39 pub fn inline_enum_const() -> E<i8, i16> {
40     *&E::A(0)
41 }
42
43 // CHECK-LABEL: @low_align_const
44 #[no_mangle]
45 pub fn low_align_const() -> E<i16, [i16; 3]> {
46 // Check that low_align_const and high_align_const use the same constant
47 // CHECK: i8* align 2 getelementptr inbounds (<{ [8 x i8] }>, <{ [8 x i8] }>* [[LOW_HIGH]], i32 0, i32 0, i32 0),
48     *&E::A(0)
49 }
50
51 // CHECK-LABEL: @high_align_const
52 #[no_mangle]
53 pub fn high_align_const() -> E<i16, i32> {
54 // Check that low_align_const and high_align_const use the same constant
55 // CHECK: i8* align 4 getelementptr inbounds (<{ [8 x i8] }>, <{ [8 x i8] }>* [[LOW_HIGH]], i32 0, i32 0, i32 0),
56     *&E::A(0)
57 }