Skip to content

Commit ba43dba

Browse files
eddybalexcrichton
authored andcommitted
trans: always register an item's symbol, even if duplicated.
1 parent 0ab80b6 commit ba43dba

File tree

3 files changed

+40
-35
lines changed

3 files changed

+40
-35
lines changed

src/librustc_trans/callee.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,15 +584,19 @@ fn get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
584584
debug!("get_fn: not casting pointer!");
585585

586586
attributes::from_fn_attrs(ccx, attrs, llfn);
587-
if let Some(id) = local_item {
587+
if local_item.is_some() {
588588
// FIXME(eddyb) Doubt all extern fn should allow unwinding.
589589
attributes::unwind(llfn, true);
590-
ccx.item_symbols().borrow_mut().insert(id, sym);
591590
}
592591

593592
llfn
594593
};
595594

595+
// Always insert into item_symbols, in case this item is exported.
596+
if let Some(id) = local_item {
597+
ccx.item_symbols().borrow_mut().insert(id, sym);
598+
}
599+
596600
ccx.instances().borrow_mut().insert(instance, llfn);
597601

598602
immediate_rvalue(llfn, fn_ptr_ty)

src/test/auxiliary/foreign_lib.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
#![crate_name="foreign_lib"]
12+
1213
#![feature(libc)]
1314

1415
pub mod rustrt {
@@ -19,3 +20,29 @@ pub mod rustrt {
1920
pub fn rust_get_test_int() -> libc::intptr_t;
2021
}
2122
}
23+
24+
pub mod rustrt2 {
25+
extern crate libc;
26+
27+
extern {
28+
pub fn rust_get_test_int() -> libc::intptr_t;
29+
}
30+
}
31+
32+
pub mod rustrt3 {
33+
// Different type, but same ABI (on all supported platforms).
34+
// Ensures that we don't ICE or trigger LLVM asserts when
35+
// importing the same symbol under different types.
36+
// See https://github.com/rust-lang/rust/issues/32740.
37+
extern {
38+
pub fn rust_get_test_int() -> *const u8;
39+
}
40+
}
41+
42+
pub fn local_uses() {
43+
unsafe {
44+
let x = rustrt::rust_get_test_int();
45+
assert_eq!(x, rustrt2::rust_get_test_int());
46+
assert_eq!(x as *const _, rustrt3::rust_get_test_int());
47+
}
48+
}

src/test/run-pass/foreign-dupe.rs

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,17 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// calling pin_thread and that's having weird side-effects.
11+
// aux-build:foreign_lib.rs
1212

13-
// pretty-expanded FIXME #23616
13+
// Check that we can still call duplicated extern (imported) functions
14+
// which were declared in another crate. See issues #32740 and #32783.
1415

15-
#![feature(libc)]
16-
17-
mod rustrt1 {
18-
extern crate libc;
19-
20-
#[link(name = "rust_test_helpers")]
21-
extern {
22-
pub fn rust_get_test_int() -> libc::intptr_t;
23-
}
24-
}
25-
26-
mod rustrt2 {
27-
extern crate libc;
28-
29-
extern {
30-
pub fn rust_get_test_int() -> libc::intptr_t;
31-
}
32-
}
33-
34-
mod rustrt3 {
35-
// Different type, but same ABI (on all supported platforms).
36-
// Ensures that we don't ICE or trigger LLVM asserts when
37-
// importing the same symbol under different types.
38-
// See https://github.com/rust-lang/rust/issues/32740.
39-
extern {
40-
pub fn rust_get_test_int() -> *const u8;
41-
}
42-
}
16+
extern crate foreign_lib;
4317

4418
pub fn main() {
4519
unsafe {
46-
let x = rustrt1::rust_get_test_int();
47-
assert_eq!(x, rustrt2::rust_get_test_int());
48-
assert_eq!(x as *const _, rustrt3::rust_get_test_int());
20+
let x = foreign_lib::rustrt::rust_get_test_int();
21+
assert_eq!(x, foreign_lib::rustrt2::rust_get_test_int());
22+
assert_eq!(x as *const _, foreign_lib::rustrt3::rust_get_test_int());
4923
}
5024
}

0 commit comments

Comments
 (0)