]> git.lizzy.rs Git - rust.git/blob - tests/codegen/consts.rs
Rollup merge of #107756 - RalfJung:miri-out-of-addresses, r=oli-obk
[rust.git] / tests / codegen / consts.rs
1 // compile-flags: -C no-prepopulate-passes
2 // min-llvm-version: 14.0
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: @alloc12 = {{.*}}, 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:@alloc[0-9]+]] = {{.*}}, align 4
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: memcpy.{{.+}}({{i8\*|ptr}} align 2 %{{[0-9]+}}, {{i8\*|ptr}} align 2 {{.*}}[[LOW_HIGH]]{{.*}}, i{{(32|64)}} 8, i1 false)
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: memcpy.{{.+}}({{i8\*|ptr}} align 4 %{{[0-9]+}}, {{i8\*|ptr}} align 4 {{.*}}[[LOW_HIGH]]{{.*}}, i{{(32|64)}} 8, i1 false)
55     *&E::A(0)
56 }