]> git.lizzy.rs Git - rust.git/blob - tests/codegen/external-no-mangle-fns.rs
Rollup merge of #107769 - compiler-errors:pointer-like, r=eholk
[rust.git] / tests / codegen / external-no-mangle-fns.rs
1 // compile-flags: -C no-prepopulate-passes
2 // `#[no_mangle]`d functions always have external linkage, i.e., no `internal` in their `define`s
3
4 #![crate_type = "lib"]
5 #![no_std]
6
7 // CHECK: define{{( dso_local)?}} void @a()
8 #[no_mangle]
9 fn a() {}
10
11 // CHECK: define{{( dso_local)?}} void @b()
12 #[no_mangle]
13 pub fn b() {}
14
15 mod private {
16     // CHECK: define{{( dso_local)?}} void @c()
17     #[no_mangle]
18     fn c() {}
19
20     // CHECK: define{{( dso_local)?}} void @d()
21     #[no_mangle]
22     pub fn d() {}
23 }
24
25 const HIDDEN: () = {
26     // CHECK: define{{( dso_local)?}} void @e()
27     #[no_mangle]
28     fn e() {}
29
30     // CHECK: define{{( dso_local)?}} void @f()
31     #[no_mangle]
32     pub fn f() {}
33 };
34
35 // The surrounding item should not accidentally become external
36 // CHECK-LABEL: ; external_no_mangle_fns::x
37 // CHECK-NEXT: ; Function Attrs:
38 // CHECK-NEXT: define internal
39 #[inline(never)]
40 fn x() {
41     // CHECK: define{{( dso_local)?}} void @g()
42     #[no_mangle]
43     fn g() {
44         x();
45     }
46
47     // CHECK: define{{( dso_local)?}} void @h()
48     #[no_mangle]
49     pub fn h() {}
50
51     // side effect to keep `x` around
52     unsafe {
53         core::ptr::read_volatile(&42);
54     }
55 }
56
57 // CHECK: define{{( dso_local)?}} void @i()
58 #[no_mangle]
59 #[inline]
60 fn i() {}
61
62 // CHECK: define{{( dso_local)?}} void @j()
63 #[no_mangle]
64 #[inline]
65 pub fn j() {}
66
67 // CHECK: define{{( dso_local)?}} void @k()
68 #[no_mangle]
69 #[inline(always)]
70 fn k() {}
71
72 // CHECK: define{{( dso_local)?}} void @l()
73 #[no_mangle]
74 #[inline(always)]
75 pub fn l() {}