Closed
Description
The following code, when compiled in release mode with -C codegen-units=2
ICEs with the error below (I initially found this with the default 16 CGUs on a much larger codebase). I'm not entirely sure that the check at https://github.com/rust-lang/rust/blob/master/src/librustc_codegen_llvm/consts.rs#L236 is needed. However, if we're moving a reference to a static to a different CGU, we shouldn't define the static at all, but only declare it. Can we get rid of the match across Item
or ForeignItem
and treat all references to a static in a different CGU as if it were foreign, regardless of whether it was foreign in HIR?
error: internal compiler error: src/librustc_codegen_llvm/consts.rs:237: Conflicting symbol names for static?
--> src/main.rs:26:5
|
26 | pub static mut external: u32 = 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
mod a {
extern "C" {
#[no_mangle]
pub static mut external: u32;
}
#[no_mangle]
pub fn foo() {
unsafe { dbg!(&external as *const u32); }
}
}
mod b {
mod c {
#[no_mangle]
pub fn bar() {
unsafe { dbg!(&external as *const u32); }
}
use super::external;
}
pub use c::bar;
#[no_mangle]
pub static mut external: u32 = 0;
}
fn main() {
a::foo();
b::bar();
chonky_func();
chonky_func2();
}
fn chonky_func() {
println!("We need to make the main module big enough");
println!("so it forces c and a to get combined");
}
fn chonky_func2() {
println!("Here's more stuff to print");
println!("And more");
}