]> git.lizzy.rs Git - rust.git/blob - src/test/codegen/consts.rs
6b4e626df924bf020be2e9d5d6e8ebb201bfc765
[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
13 #![crate_type = "lib"]
14
15 // Below, these constants are defined as enum variants that by itself would
16 // have a lower alignment than the enum type. Ensure that we mark them
17 // correctly with the higher alignment of the enum.
18
19 // CHECK: @STATIC = {{.*}}, align 4
20
21 // This checks the constants from inline_enum_const
22 // CHECK: @const{{[0-9]+}} = {{.*}}, align 2
23
24 // This checks the constants from {low,high}_align_const, they share the same
25 // constant, but the alignment differs, so the higher one should be used
26 // CHECK: @const{{[0-9]+}} = {{.*}}, align 4
27
28 #[derive(Copy, Clone)]
29
30 // repr(i16) is required for the {low,high}_align_const test
31 #[repr(i16)]
32 pub enum E<A, B> {
33     A(A),
34     B(B),
35 }
36
37 #[no_mangle]
38 pub static STATIC: E<i16, i32> = E::A(0);
39
40 // CHECK-LABEL: @static_enum_const
41 #[no_mangle]
42 pub fn static_enum_const() -> E<i16, i32> {
43    STATIC
44 }
45
46 // CHECK-LABEL: @inline_enum_const
47 #[no_mangle]
48 pub fn inline_enum_const() -> E<i8, i16> {
49     E::A(0)
50 }
51
52 // CHECK-LABEL: @low_align_const
53 #[no_mangle]
54 pub fn low_align_const() -> E<i16, [i16; 3]> {
55 // Check that low_align_const and high_align_const use the same constant
56 // CHECK: call void @llvm.memcpy.{{.*}}(i8* %{{[0-9]+}}, i8* {{.*}} [[LOW_HIGH:@const[0-9]+]]
57     E::A(0)
58 }
59
60 // CHECK-LABEL: @high_align_const
61 #[no_mangle]
62 pub fn high_align_const() -> E<i16, i32> {
63 // Check that low_align_const and high_align_const use the same constant
64 // CHECK: call void @llvm.memcpy.{{.*}}(i8* %{{[0-9]}}, i8* {{.*}} [[LOW_HIGH]]
65     E::A(0)
66 }