]> git.lizzy.rs Git - rust.git/blob - src/test/codegen/external-no-mangle-fns.rs
Enable emission of alignment attrs for pointer params
[rust.git] / src / test / codegen / external-no-mangle-fns.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: -C no-prepopulate-passes
12 // `#[no_mangle]`d functions always have external linkage, i.e., no `internal` in their `define`s
13
14 #![crate_type = "lib"]
15 #![no_std]
16
17 // CHECK: define void @a()
18 #[no_mangle]
19 fn a() {}
20
21 // CHECK: define void @b()
22 #[no_mangle]
23 pub fn b() {}
24
25 mod private {
26     // CHECK: define void @c()
27     #[no_mangle]
28     fn c() {}
29
30     // CHECK: define void @d()
31     #[no_mangle]
32     pub fn d() {}
33 }
34
35 const HIDDEN: () = {
36     // CHECK: define void @e()
37     #[no_mangle]
38     fn e() {}
39
40     // CHECK: define void @f()
41     #[no_mangle]
42     pub fn f() {}
43 };
44
45 // The surrounding item should not accidentally become external
46 // CHECK: define internal{{.*}} void @_ZN22external_no_mangle_fns1x
47 #[inline(never)]
48 fn x() {
49     // CHECK: define void @g()
50     #[no_mangle]
51     fn g() {
52         x();
53     }
54
55     // CHECK: define void @h()
56     #[no_mangle]
57     pub fn h() {}
58
59     // side effect to keep `x` around
60     unsafe {
61         core::ptr::read_volatile(&42);
62     }
63 }