[gccrs COMMIT] gccrs: add null guard for failed builtin expansion
gerris.rs@gmail.com
gerris.rs@gmail.com
Tue Sep 15 09:39:01 GMT 2026
From: Philip Herron <herron.philip@googlemail.com>
Fixes Rust-GCC/gccrs#4477
gcc/rust/ChangeLog:
* expand/rust-expand-visitor.cc (builtin_derive_item): check for null and remove
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
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/3b0b57e0033f4198e492abcdbd65c00d83c734ae
The commit has been mentioned in the following issue(s):
- Rust-GCC/gccrs#4477: https://github.com/Rust-GCC/gccrs/issues/4477
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4895
gcc/rust/expand/rust-expand-visitor.cc | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/gcc/rust/expand/rust-expand-visitor.cc b/gcc/rust/expand/rust-expand-visitor.cc
index 3a042ac9a..e78f72305 100644
--- a/gcc/rust/expand/rust-expand-visitor.cc
+++ b/gcc/rust/expand/rust-expand-visitor.cc
@@ -49,13 +49,22 @@ static std::vector<std::unique_ptr<AST::Item>>
builtin_derive_item (AST::Item &item, const AST::Attribute &derive,
BuiltinMacro to_derive, MacroExpander &expander)
{
+ auto &mappings = Analysis::Mappings::get ();
auto item_source = AST::Builder::get_item_source (expander.crate);
auto items
= AST::DeriveVisitor::derive (item, derive, to_derive, item_source);
- for (auto &item : items)
- Analysis::Mappings::get ().add_derived_node (item->get_node_id ());
+ for (auto it = items.begin (); it != items.end ();)
+ {
+ if (*it == nullptr)
+ it = items.erase (it);
+ else
+ {
+ mappings.add_derived_node ((*it)->get_node_id ());
+ ++it;
+ }
+ }
return items;
}
base-commit: 883e65a539a9c84c6cb29f19ddca1bca47daf163
--
2.55.0
More information about the Gcc-rust
mailing list