From: Tom Schollenberger Date: Mon, 12 May 2025 02:57:28 +0000 (-0400) Subject: gccrs: Fix NR2 ICE in visit_attributes X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6524c0687aeeaee3c008b89dc328ee472bd1efea;p=thirdparty%2Fgcc.git gccrs: Fix NR2 ICE in visit_attributes Undefined attribute macros have no proc macro definition, which results in a failing `rust_assert`. This changes that assert to an if statement, that returns early if there is no proc macro definition. Fixes #3661. gcc/rust/ChangeLog: * resolve/rust-early-name-resolver-2.0.cc (Early::visit_attributes): rust_assert to if gcc/testsuite/ChangeLog: * rust/compile/issue-3661.rs: Test NR2 has expected behavior Signed-off-by: Tom Schollenberger --- diff --git a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc index 1e29c7967b8..b00bd1ee7f8 100644 --- a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc +++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc @@ -350,7 +350,8 @@ Early::visit_attributes (std::vector &attrs) auto pm_def = mappings.lookup_attribute_proc_macro_def ( definition->get_node_id ()); - rust_assert (pm_def.has_value ()); + if (!pm_def.has_value ()) + return; mappings.insert_attribute_proc_macro_invocation (attr.get_path (), pm_def.value ()); diff --git a/gcc/testsuite/rust/compile/issue-3661.rs b/gcc/testsuite/rust/compile/issue-3661.rs new file mode 100644 index 00000000000..8d03c3630d5 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3661.rs @@ -0,0 +1,10 @@ +pub macro m($inner_str:expr) { + #[m = $inner_str] + // { dg-error "macro not found" "" { target *-*-* } .-1 } + + struct S; +} + +fn main() { + m!(stringify!(foo)); +}