From 9862af0658e08d279fd8a292d568492c94e31477 Mon Sep 17 00:00:00 2001 From: Owen Avery Date: Wed, 2 Jul 2025 21:38:56 -0400 Subject: [PATCH] gccrs: Load modules during CfgStrip phase TopLevel would ignore just-loaded modules but Early and ExpandVisitor wouldn't. The latter would produce errors when it hit attributes which should have been indirectly CfgStrip'd away. gcc/rust/ChangeLog: * expand/rust-cfg-strip.cc (CfgStrip::visit): Load unloaded modules. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Assume modules have been loaded by CfgStrip. Signed-off-by: Owen Avery --- gcc/rust/expand/rust-cfg-strip.cc | 19 +++++++++-------- .../rust-toplevel-name-resolver-2.0.cc | 21 ------------------- 2 files changed, 10 insertions(+), 30 deletions(-) diff --git a/gcc/rust/expand/rust-cfg-strip.cc b/gcc/rust/expand/rust-cfg-strip.cc index 774e2b46b94..ac795f7259d 100644 --- a/gcc/rust/expand/rust-cfg-strip.cc +++ b/gcc/rust/expand/rust-cfg-strip.cc @@ -1765,16 +1765,17 @@ CfgStrip::visit (AST::Module &module) return; } - // A loaded module might have inner attributes - if (module.get_kind () == AST::Module::ModuleKind::LOADED) + if (module.get_kind () == AST::Module::UNLOADED) { - // strip test based on inner attrs - expand_cfg_attrs (module.get_inner_attrs ()); - if (fails_cfg_with_expand (module.get_inner_attrs ())) - { - module.mark_for_strip (); - return; - } + module.load_items (); + } + + // strip test based on inner attrs + expand_cfg_attrs (module.get_inner_attrs ()); + if (fails_cfg_with_expand (module.get_inner_attrs ())) + { + module.mark_for_strip (); + return; } // strip items if required diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc index a7b442d5b44..713dce6b95a 100644 --- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc +++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc @@ -101,27 +101,6 @@ TopLevel::go (AST::Crate &crate) void TopLevel::visit (AST::Module &module) { - // Parse the module's items if they haven't been expanded and the file - // should be parsed (i.e isn't hidden behind an untrue or impossible cfg - // directive - // TODO: make sure this is right - // TODO: avoid loading items if cfg attributes are present? - // might not be needed if this runs after early resolution? - // This was copied from the old early resolver method - // 'accumulate_escaped_macros' - if (module.get_kind () == AST::Module::UNLOADED) - { - module.load_items (); - - // If the module was previously unloaded, then we don't want to visit it - // this time around as the CfgStrip hasn't run on its inner items yet. - // Skip it for now, mark the visitor as dirty and try again - - dirty = true; - - return; - } - DefaultResolver::visit (module); if (Analysis::Mappings::get ().lookup_ast_module (module.get_node_id ()) -- 2.47.2