From: lenny.chiadmi-delage Date: Fri, 19 Dec 2025 12:34:45 +0000 (+0000) Subject: gccrs: respect cfg_attr expansion X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a088603cbbaa2a8ffad2551ca9490045eb415e25;p=thirdparty%2Fgcc.git gccrs: respect cfg_attr expansion Fix cfg_attr expansion and feature gate attribute handling Fixes Rust-GCC#4245 gcc/rust/ChangeLog: * checks/errors/feature/rust-feature-gate.cc (FeatureGate::visit): Added handling for META_ITEM type attributes to properly process feature gates. * expand/rust-cfg-strip.cc (expand_cfg_attrs): Fixed a bug where newly inserted cfg_attr attributes wheren't being reprocessed, and cleaned up the loop increment logic. Signed-off-by: lenny.chiadmi-delage --- diff --git a/gcc/rust/checks/errors/feature/rust-feature-gate.cc b/gcc/rust/checks/errors/feature/rust-feature-gate.cc index 9df822b7e1c..e5170b77808 100644 --- a/gcc/rust/checks/errors/feature/rust-feature-gate.cc +++ b/gcc/rust/checks/errors/feature/rust-feature-gate.cc @@ -69,6 +69,22 @@ FeatureGate::visit (AST::Crate &crate) valid_lib_features.emplace (name_str, item->get_locus ()); } } + else if (type == AST::AttrInput::AttrInputType::META_ITEM) + { + const auto &meta_item + = static_cast ( + attr_input); + for (const auto &item : meta_item.get_items ()) + { + const auto &name_str = item->as_string (); + + // TODO: detect duplicates + if (auto tname = Feature::as_name (name_str)) + valid_lang_features.insert (tname.value ()); + else + valid_lib_features.emplace (name_str, item->get_locus ()); + } + } } } diff --git a/gcc/rust/expand/rust-cfg-strip.cc b/gcc/rust/expand/rust-cfg-strip.cc index 3c5e74e7aae..e8c6c378942 100644 --- a/gcc/rust/expand/rust-cfg-strip.cc +++ b/gcc/rust/expand/rust-cfg-strip.cc @@ -124,6 +124,12 @@ expand_cfg_attrs (AST::AttrVec &attrs) attrs.insert (attrs.begin () + i, std::make_move_iterator (new_attrs.begin ()), std::make_move_iterator (new_attrs.end ())); + + /* Decrement i so that the for loop's i++ will bring us back to + * position i, allowing us to reprocess the newly inserted + * attribute (in case it's also a cfg_attr that needs expansion) + */ + i--; } /* do something - if feature (first token in tree) is in fact enabled, @@ -133,10 +139,6 @@ expand_cfg_attrs (AST::AttrVec &attrs) * recursive, so check for expanded attributes being recursive and * possibly recursively call the expand_attrs? */ } - else - { - i++; - } } attrs.shrink_to_fit (); }