]> git.lizzy.rs Git - rust.git/blob - src/test/codegen/external-no-mangle-statics.rs
59d829633e55c497c87be79c04eed3f0bfc88133
[rust.git] / src / test / codegen / external-no-mangle-statics.rs
1 // Copyright 2018 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: -O
12 // `#[no_mangle]`d static variables always have external linkage, i.e. no `internal` in their
13 // definitions
14
15 #![crate_type = "lib"]
16 #![no_std]
17
18 // CHECK: @A = local_unnamed_addr constant
19 #[no_mangle]
20 static A: u8 = 0;
21
22 // CHECK: @B = local_unnamed_addr global
23 #[no_mangle]
24 static mut B: u8 = 0;
25
26 // CHECK: @C = local_unnamed_addr constant
27 #[no_mangle]
28 pub static C: u8 = 0;
29
30 // CHECK: @D = local_unnamed_addr global
31 #[no_mangle]
32 pub static mut D: u8 = 0;
33
34 mod private {
35     // CHECK: @E = local_unnamed_addr constant
36     #[no_mangle]
37     static E: u8 = 0;
38
39     // CHECK: @F = local_unnamed_addr global
40     #[no_mangle]
41     static mut F: u8 = 0;
42
43     // CHECK: @G = local_unnamed_addr constant
44     #[no_mangle]
45     pub static G: u8 = 0;
46
47     // CHECK: @H = local_unnamed_addr global
48     #[no_mangle]
49     pub static mut H: u8 = 0;
50 }
51
52 const HIDDEN: () = {
53     // CHECK: @I = local_unnamed_addr constant
54     #[no_mangle]
55     static I: u8 = 0;
56
57     // CHECK: @J = local_unnamed_addr global
58     #[no_mangle]
59     static mut J: u8 = 0;
60
61     // CHECK: @K = local_unnamed_addr constant
62     #[no_mangle]
63     pub static K: u8 = 0;
64
65     // CHECK: @L = local_unnamed_addr global
66     #[no_mangle]
67     pub static mut L: u8 = 0;
68 };
69
70 // The surrounding item should not accidentally become external
71 fn x() {
72     // CHECK: @M = local_unnamed_addr constant
73     #[no_mangle]
74     static M: fn() = x;
75
76     // CHECK: @N = local_unnamed_addr global
77     #[no_mangle]
78     static mut N: u8 = 0;
79
80     // CHECK: @O = local_unnamed_addr constant
81     #[no_mangle]
82     pub static O: u8 = 0;
83
84     // CHECK: @P = local_unnamed_addr global
85     #[no_mangle]
86     pub static mut P: u8 = 0;
87 }
88 // CHECK: define internal void @_ZN26external_no_mangle_statics1x{{.*$}}