From: "lenny.chiadmi-delage" <[email protected]>
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 <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.
Commit on github:
https://github.com/Rust-GCC/gccrs/commit/5712c79af097da357057d57b6de0f6697b8fa1f1
The commit is not linked to any pull-request
.../checks/errors/feature/rust-feature-gate.cc | 16 ++++++++++++++++
gcc/rust/expand/rust-cfg-strip.cc | 10 ++++++----
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/gcc/rust/checks/errors/feature/rust-feature-gate.cc
b/gcc/rust/checks/errors/feature/rust-feature-gate.cc
index 9df822b7e..e5170b778 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<const AST::AttrInputMetaItemContainer &> (
+ 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 3c5e74e7a..e8c6c3789 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 ();
}
base-commit: 49002a872e07a14ad4e17a0dcdca60096c1ee62b
--
2.52.0