Skip to content

Contents of reachable statics is reachable #115114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions compiler/rustc_passes/src/reachable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,11 @@ impl<'tcx> Visitor<'tcx> for ReachableContext<'tcx> {
self.worklist.push(def_id);
} else {
match res {
// If this path leads to a constant, then we need to
// recurse into the constant to continue finding
// items that are reachable.
Res::Def(DefKind::Const | DefKind::AssocConst, _) => {
// Reachable constants and reachable statics can have their contents inlined
// into other crates. Mark them as reachable and recurse into their body.
Res::Def(DefKind::Const | DefKind::AssocConst | DefKind::Static(_), _) => {
self.worklist.push(def_id);
}

// If this wasn't a static, then the destination is
// surely reachable.
_ => {
self.reachable_symbols.insert(def_id);
}
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/cross-crate/auxiliary/static_init_aux.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
pub static V: &u32 = &X;
pub static F: fn() = f;
pub static G: fn() = G0;

static X: u32 = 42;
static G0: fn() = g;

pub fn v() -> *const u32 {
V
}

fn f() {}

fn g() {}
3 changes: 3 additions & 0 deletions tests/ui/cross-crate/static-init.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Regression test for #84455 and #115052.
// run-pass
// aux-build:static_init_aux.rs
extern crate static_init_aux as aux;

static V: &u32 = aux::V;
static F: fn() = aux::F;
static G: fn() = aux::G;

fn v() -> *const u32 {
V
Expand All @@ -12,4 +14,5 @@ fn v() -> *const u32 {
fn main() {
assert_eq!(aux::v(), crate::v());
F();
G();
}