Skip to content

Commit fe5fb92

Browse files
committed
Fix exports with #[inline(always)]
1 parent f33a562 commit fe5fb92

File tree

5 files changed

+68
-18
lines changed

5 files changed

+68
-18
lines changed

src/librustc_middle/mir/mono.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,9 @@ impl<'tcx> MonoItem<'tcx> {
9191
match *self {
9292
MonoItem::Fn(ref instance) => {
9393
let entry_def_id = tcx.entry_fn(LOCAL_CRATE).map(|(id, _)| id);
94-
// If this function isn't inlined or otherwise has explicit
95-
// linkage or an extern indicator, then we'll be creating a
96-
// globally shared version.
97-
if self.explicit_linkage(tcx).is_some()
94+
// If this function isn't inlined or otherwise has an extern
95+
// indicator, then we'll be creating a globally shared version.
96+
if tcx.codegen_fn_attrs(instance.def_id()).contains_extern_indicator()
9897
|| !instance.def.generates_cgu_internal_copy(tcx)
9998
|| Some(instance.def_id()) == entry_def_id.map(LocalDefId::to_def_id)
10099
{
@@ -103,12 +102,8 @@ impl<'tcx> MonoItem<'tcx> {
103102

104103
// At this point we don't have explicit linkage and we're an
105104
// inlined function. If we're inlining into all CGUs then we'll
106-
// be creating a local copy per CGU. We need to watch out here
107-
// for an extern indicator as we don't want to optimise away
108-
// inlined functions that should be exported.
109-
if generate_cgu_internal_copies
110-
&& !tcx.codegen_fn_attrs(instance.def_id()).contains_extern_indicator()
111-
{
105+
// be creating a local copy per CGU.
106+
if generate_cgu_internal_copies {
112107
return InstantiationMode::LocalCopy;
113108
}
114109

src/test/codegen/cdylib-external-inline-fns.rs

+20
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,23 @@ extern "C" fn c() {}
2121
#[export_name = "d"]
2222
#[inline]
2323
extern "C" fn d() {}
24+
25+
// CHECK: define void @e()
26+
#[no_mangle]
27+
#[inline(always)]
28+
pub extern "C" fn e() {}
29+
30+
// CHECK: define void @f()
31+
#[export_name = "f"]
32+
#[inline(always)]
33+
pub extern "C" fn f() {}
34+
35+
// CHECK: define void @g()
36+
#[no_mangle]
37+
#[inline(always)]
38+
extern "C" fn g() {}
39+
40+
// CHECK: define void @h()
41+
#[export_name = "h"]
42+
#[inline(always)]
43+
extern "C" fn h() {}

src/test/codegen/export-no-mangle.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,21 @@ mod private {
1111
#[export_name = "BAR"]
1212
static BAR: u32 = 3;
1313

14-
// CHECK: void @foo()
14+
// CHECK: void @a()
1515
#[no_mangle]
16-
pub extern fn foo() {}
16+
pub extern fn a() {}
1717

18-
// CHECK: void @bar()
19-
#[export_name = "bar"]
20-
extern fn bar() {}
18+
// CHECK: void @b()
19+
#[export_name = "b"]
20+
extern fn b() {}
2121

22-
// CHECK: void @baz()
23-
#[export_name = "baz"]
22+
// CHECK: void @c()
23+
#[export_name = "c"]
2424
#[inline]
25-
extern fn baz() {}
25+
extern fn c() {}
26+
27+
// CHECK: void @d()
28+
#[export_name = "d"]
29+
#[inline(always)]
30+
extern fn d() {}
2631
}

src/test/codegen/external-no-mangle-fns.rs

+10
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,13 @@ fn i() {}
6363
#[no_mangle]
6464
#[inline]
6565
pub fn j() {}
66+
67+
// CHECK: define void @k()
68+
#[no_mangle]
69+
#[inline(always)]
70+
fn k() {}
71+
72+
// CHECK: define void @l()
73+
#[no_mangle]
74+
#[inline(always)]
75+
pub fn l() {}

src/test/codegen/staticlib-external-inline-fns.rs

+20
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,23 @@ extern "C" fn c() {}
2121
#[export_name = "d"]
2222
#[inline]
2323
extern "C" fn d() {}
24+
25+
// CHECK: define void @e()
26+
#[no_mangle]
27+
#[inline(always)]
28+
pub extern "C" fn e() {}
29+
30+
// CHECK: define void @f()
31+
#[export_name = "f"]
32+
#[inline(always)]
33+
pub extern "C" fn f() {}
34+
35+
// CHECK: define void @g()
36+
#[no_mangle]
37+
#[inline(always)]
38+
extern "C" fn g() {}
39+
40+
// CHECK: define void @h()
41+
#[export_name = "h"]
42+
#[inline(always)]
43+
extern "C" fn h() {}

0 commit comments

Comments
 (0)