https://gcc.gnu.org/g:69efc872fe09b374e6f48e9646a1e3d627a4ce58
commit r17-5135-g69efc872fe09b374e6f48e9646a1e3d627a4ce58 Author: Philip Herron <[email protected]> Date: Mon Sep 14 21:21:07 2026 +0100 gccrs: add null guard for failed builtin expansion 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 <[email protected]> Diff: --- 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 3a042ac9a9c3..e78f723053b3 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; }
