]> git.lizzy.rs Git - rust.git/blob - src/test/codegen/consts.rs
Enable emission of alignment attrs for pointer params
[rust.git] / src / test / codegen / consts.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // compile-flags: -C no-prepopulate-passes
12 // ignore-tidy-linelength
13 // min-llvm-version 7.0
14
15 #![crate_type = "lib"]
16
17 // Below, these constants are defined as enum variants that by itself would
18 // have a lower alignment than the enum type. Ensure that we mark them
19 // correctly with the higher alignment of the enum.
20
21 // CHECK: @STATIC = {{.*}}, align 4
22
23 // This checks the constants from inline_enum_const
24 // CHECK: @{{[0-9]+}} = {{.*}}, align 2
25
26 // This checks the constants from {low,high}_align_const, they share the same
27 // constant, but the alignment differs, so the higher one should be used
28 // CHECK: [[LOW_HIGH:@[0-9]+]] = {{.*}}, align 4
29
30 #[derive(Copy, Clone)]
31
32 // repr(i16) is required for the {low,high}_align_const test
33 #[repr(i16)]
34 pub enum E<A, B> {
35     A(A),
36     B(B),
37 }
38
39 #[no_mangle]
40 pub static STATIC: E<i16, i32> = E::A(0);
41
42 // CHECK-LABEL: @static_enum_const
43 #[no_mangle]
44 pub fn static_enum_const() -> E<i16, i32> {
45    STATIC
46 }
47
48 // CHECK-LABEL: @inline_enum_const
49 #[no_mangle]
50 pub fn inline_enum_const() -> E<i8, i16> {
51     *&E::A(0)
52 }
53
54 // CHECK-LABEL: @low_align_const
55 #[no_mangle]
56 pub fn low_align_const() -> E<i16, [i16; 3]> {
57 // Check that low_align_const and high_align_const use the same constant
58 // CHECK: i8* align 2 getelementptr inbounds (<{ [8 x i8] }>, <{ [8 x i8] }>* [[LOW_HIGH]], i32 0, i32 0, i32 0),
59     *&E::A(0)
60 }
61
62 // CHECK-LABEL: @high_align_const
63 #[no_mangle]
64 pub fn high_align_const() -> E<i16, i32> {
65 // Check that low_align_const and high_align_const use the same constant
66 // CHECK: i8* align 4 getelementptr inbounds (<{ [8 x i8] }>, <{ [8 x i8] }>* [[LOW_HIGH]], i32 0, i32 0, i32 0),
67     *&E::A(0)
68 }