https://gcc.gnu.org/g:f870c29e2c450253b48a2c6246de48d4f5e275ea

commit f870c29e2c450253b48a2c6246de48d4f5e275ea
Author: Tom Schollenberger <tss2...@g.rit.edu>
Date:   Sun May 11 22:57:28 2025 -0400

    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 <tss2...@g.rit.edu>

Diff:
---
 gcc/rust/resolve/rust-early-name-resolver-2.0.cc |  3 ++-
 gcc/testsuite/rust/compile/issue-3661.rs         | 10 ++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

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 73d71ca185a2..1dc63f417e2c 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<AST::Attribute> &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 000000000000..8d03c3630d56
--- /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));
+}

Reply via email to