1
Fork 0

Contents of reachable statics is reachable

This commit is contained in:
Tomasz Miąsko 2023-08-22 00:00:00 +00:00
parent 3e9e5745df
commit 0383131f7f
3 changed files with 10 additions and 7 deletions

View file

@ -98,15 +98,11 @@ impl<'tcx> Visitor<'tcx> for ReachableContext<'tcx> {
self.worklist.push(def_id); self.worklist.push(def_id);
} else { } else {
match res { match res {
// If this path leads to a constant, then we need to // Reachable constants and reachable statics can have their contents inlined
// recurse into the constant to continue finding // into other crates. Mark them as reachable and recurse into their body.
// items that are reachable. Res::Def(DefKind::Const | DefKind::AssocConst | DefKind::Static(_), _) => {
Res::Def(DefKind::Const | DefKind::AssocConst, _) => {
self.worklist.push(def_id); self.worklist.push(def_id);
} }
// If this wasn't a static, then the destination is
// surely reachable.
_ => { _ => {
self.reachable_symbols.insert(def_id); self.reachable_symbols.insert(def_id);
} }

View file

@ -1,10 +1,14 @@
pub static V: &u32 = &X; pub static V: &u32 = &X;
pub static F: fn() = f; pub static F: fn() = f;
pub static G: fn() = G0;
static X: u32 = 42; static X: u32 = 42;
static G0: fn() = g;
pub fn v() -> *const u32 { pub fn v() -> *const u32 {
V V
} }
fn f() {} fn f() {}
fn g() {}

View file

@ -1,9 +1,11 @@
// Regression test for #84455 and #115052.
// run-pass // run-pass
// aux-build:static_init_aux.rs // aux-build:static_init_aux.rs
extern crate static_init_aux as aux; extern crate static_init_aux as aux;
static V: &u32 = aux::V; static V: &u32 = aux::V;
static F: fn() = aux::F; static F: fn() = aux::F;
static G: fn() = aux::G;
fn v() -> *const u32 { fn v() -> *const u32 {
V V
@ -12,4 +14,5 @@ fn v() -> *const u32 {
fn main() { fn main() {
assert_eq!(aux::v(), crate::v()); assert_eq!(aux::v(), crate::v());
F(); F();
G();
} }