]> git.lizzy.rs Git - rust.git/commitdiff
Fix exports with `#[inline(always)]`
authorNathan Corbyn <me@nathancorbyn.com>
Tue, 9 Jun 2020 14:49:59 +0000 (15:49 +0100)
committerNathan Corbyn <me@nathancorbyn.com>
Mon, 15 Jun 2020 08:40:56 +0000 (09:40 +0100)
src/librustc_middle/mir/mono.rs
src/test/codegen/cdylib-external-inline-fns.rs
src/test/codegen/export-no-mangle.rs
src/test/codegen/external-no-mangle-fns.rs
src/test/codegen/staticlib-external-inline-fns.rs

index 886690da212d3ef12dc89c593aaa5bf568fea4d9..24d324ff09c4c3d2554d08294c286f05d4b6863a 100644 (file)
@@ -91,10 +91,9 @@ pub fn instantiation_mode(&self, tcx: TyCtxt<'tcx>) -> InstantiationMode {
         match *self {
             MonoItem::Fn(ref instance) => {
                 let entry_def_id = tcx.entry_fn(LOCAL_CRATE).map(|(id, _)| id);
-                // If this function isn't inlined or otherwise has explicit
-                // linkage or an extern indicator, then we'll be creating a
-                // globally shared version.
-                if self.explicit_linkage(tcx).is_some()
+                // If this function isn't inlined or otherwise has an extern
+                // indicator, then we'll be creating a globally shared version.
+                if tcx.codegen_fn_attrs(instance.def_id()).contains_extern_indicator()
                     || !instance.def.generates_cgu_internal_copy(tcx)
                     || Some(instance.def_id()) == entry_def_id.map(LocalDefId::to_def_id)
                 {
@@ -103,12 +102,8 @@ pub fn instantiation_mode(&self, tcx: TyCtxt<'tcx>) -> InstantiationMode {
 
                 // At this point we don't have explicit linkage and we're an
                 // inlined function. If we're inlining into all CGUs then we'll
-                // be creating a local copy per CGU. We need to watch out here
-                // for an extern indicator as we don't want to optimise away
-                // inlined functions that should be exported.
-                if generate_cgu_internal_copies
-                    && !tcx.codegen_fn_attrs(instance.def_id()).contains_extern_indicator()
-                {
+                // be creating a local copy per CGU. 
+                if generate_cgu_internal_copies {
                     return InstantiationMode::LocalCopy;
                 }
 
index 58f806b5a1f34091fe6741fc6ff930458d9a9dce..519be6b6a99a43d2d870ee6dfcad1117f264a753 100644 (file)
@@ -21,3 +21,23 @@ extern "C" fn c() {}
 #[export_name = "d"]
 #[inline]
 extern "C" fn d() {}
+
+// CHECK: define void @e()
+#[no_mangle]
+#[inline(always)]
+pub extern "C" fn e() {}
+
+// CHECK: define void @f()
+#[export_name = "f"]
+#[inline(always)]
+pub extern "C" fn f() {}
+
+// CHECK: define void @g()
+#[no_mangle]
+#[inline(always)]
+extern "C" fn g() {}
+
+// CHECK: define void @h()
+#[export_name = "h"]
+#[inline(always)]
+extern "C" fn h() {}
index a52fac37021ddffde0e84917ad63061727362631..11427ae38822ff0f47b2759aa4ffb80f6584f9a7 100644 (file)
@@ -11,16 +11,21 @@ mod private {
     #[export_name = "BAR"]
     static BAR: u32 = 3;
 
-    // CHECK: void @foo()
+    // CHECK: void @a()
     #[no_mangle]
-    pub extern fn foo() {}
+    pub extern fn a() {}
 
-    // CHECK: void @bar()
-    #[export_name = "bar"]
-    extern fn bar() {}
+    // CHECK: void @b()
+    #[export_name = "b"]
+    extern fn b() {}
 
-    // CHECK: void @baz()
-    #[export_name = "baz"]
+    // CHECK: void @c()
+    #[export_name = "c"]
     #[inline]
-    extern fn baz() {}
+    extern fn c() {}
+    
+    // CHECK: void @d()
+    #[export_name = "d"]
+    #[inline(always)]
+    extern fn d() {}
 }
index aefa9ce21c3ee98dcc7eff91a50e9ff670b68e00..41820b057f1ef27710bf098403d3829daee3dac8 100644 (file)
@@ -63,3 +63,13 @@ fn i() {}
 #[no_mangle]
 #[inline]
 pub fn j() {}
+
+// CHECK: define void @k()
+#[no_mangle]
+#[inline(always)]
+fn k() {}
+
+// CHECK: define void @l()
+#[no_mangle]
+#[inline(always)]
+pub fn l() {}
index 8f55a5303311cb3ea17233e36228cad0922de4df..8876ab7376afe3ce5ca7b7c400c86251efae375e 100644 (file)
@@ -21,3 +21,23 @@ extern "C" fn c() {}
 #[export_name = "d"]
 #[inline]
 extern "C" fn d() {}
+
+// CHECK: define void @e()
+#[no_mangle]
+#[inline(always)]
+pub extern "C" fn e() {}
+
+// CHECK: define void @f()
+#[export_name = "f"]
+#[inline(always)]
+pub extern "C" fn f() {}
+
+// CHECK: define void @g()
+#[no_mangle]
+#[inline(always)]
+extern "C" fn g() {}
+
+// CHECK: define void @h()
+#[export_name = "h"]
+#[inline(always)]
+extern "C" fn h() {}