]> git.lizzy.rs Git - rust.git/commitdiff
trans: always register an item's symbol, even if duplicated.
authorEduard Burtescu <edy.burt@gmail.com>
Thu, 14 Apr 2016 05:39:23 +0000 (08:39 +0300)
committerEduard Burtescu <edy.burt@gmail.com>
Thu, 14 Apr 2016 05:39:23 +0000 (08:39 +0300)
src/librustc_trans/callee.rs
src/test/auxiliary/foreign_lib.rs
src/test/run-pass/foreign-dupe.rs

index 7675e1de958277426a9a2f9b374e6ee342caf537..8c22ddbb462c025c5ce1dfa5c8fbec40cbe2094c 100644 (file)
@@ -582,15 +582,19 @@ fn is_named_tuple_constructor(tcx: &TyCtxt, def_id: DefId) -> bool {
         debug!("get_fn: not casting pointer!");
 
         attributes::from_fn_attrs(ccx, attrs, llfn);
-        if let Some(id) = local_item {
+        if local_item.is_some() {
             // FIXME(eddyb) Doubt all extern fn should allow unwinding.
             attributes::unwind(llfn, true);
-            ccx.item_symbols().borrow_mut().insert(id, sym);
         }
 
         llfn
     };
 
+    // Always insert into item_symbols, in case this item is exported.
+    if let Some(id) = local_item {
+        ccx.item_symbols().borrow_mut().insert(id, sym);
+    }
+
     ccx.instances().borrow_mut().insert(instance, llfn);
 
     immediate_rvalue(llfn, fn_ptr_ty)
index 92239ce55981c808dfd0991c4a7eaa2906377223..460d0a0088ce2918813c5374d8558d63a99409fd 100644 (file)
@@ -9,6 +9,7 @@
 // except according to those terms.
 
 #![crate_name="foreign_lib"]
+
 #![feature(libc)]
 
 pub mod rustrt {
@@ -19,3 +20,29 @@ pub mod rustrt {
         pub fn rust_get_test_int() -> libc::intptr_t;
     }
 }
+
+pub mod rustrt2 {
+    extern crate libc;
+
+    extern {
+        pub fn rust_get_test_int() -> libc::intptr_t;
+    }
+}
+
+pub mod rustrt3 {
+    // Different type, but same ABI (on all supported platforms).
+    // Ensures that we don't ICE or trigger LLVM asserts when
+    // importing the same symbol under different types.
+    // See https://github.com/rust-lang/rust/issues/32740.
+    extern {
+        pub fn rust_get_test_int() -> *const u8;
+    }
+}
+
+pub fn local_uses() {
+    unsafe {
+        let x = rustrt::rust_get_test_int();
+        assert_eq!(x, rustrt2::rust_get_test_int());
+        assert_eq!(x as *const _, rustrt3::rust_get_test_int());
+    }
+}
index 4e06c434ccc1203b597f4cb066e516df95138965..fb162d8793356a35f625a49a5091b105ab56f312 100644 (file)
@@ -8,41 +8,18 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-// calling pin_thread and that's having weird side-effects.
+// aux-build:foreign_lib.rs
 
-#![feature(libc)]
+// Check that we can still call duplicated extern (imported) functions
+// which were declared in another crate. See issues #32740 and #32783.
 
-mod rustrt1 {
-    extern crate libc;
 
-    #[link(name = "rust_test_helpers")]
-    extern {
-        pub fn rust_get_test_int() -> libc::intptr_t;
-    }
-}
-
-mod rustrt2 {
-    extern crate libc;
-
-    extern {
-        pub fn rust_get_test_int() -> libc::intptr_t;
-    }
-}
-
-mod rustrt3 {
-    // Different type, but same ABI (on all supported platforms).
-    // Ensures that we don't ICE or trigger LLVM asserts when
-    // importing the same symbol under different types.
-    // See https://github.com/rust-lang/rust/issues/32740.
-    extern {
-        pub fn rust_get_test_int() -> *const u8;
-    }
-}
+extern crate foreign_lib;
 
 pub fn main() {
     unsafe {
-        let x = rustrt1::rust_get_test_int();
-        assert_eq!(x, rustrt2::rust_get_test_int());
-        assert_eq!(x as *const _, rustrt3::rust_get_test_int());
+        let x = foreign_lib::rustrt::rust_get_test_int();
+        assert_eq!(x, foreign_lib::rustrt2::rust_get_test_int());
+        assert_eq!(x as *const _, foreign_lib::rustrt3::rust_get_test_int());
     }
 }