]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Fix NR2 ICE in visit_attributes
authorTom Schollenberger <tss2344@g.rit.edu>
Mon, 12 May 2025 02:57:28 +0000 (22:57 -0400)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 5 Aug 2025 14:36:43 +0000 (16:36 +0200)
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 <tss2344@g.rit.edu>
gcc/rust/resolve/rust-early-name-resolver-2.0.cc
gcc/testsuite/rust/compile/issue-3661.rs [new file with mode: 0644]

index 1e29c7967b82a1c418f12b3e80ffca373b731374..b00bd1ee7f8ec7d761f9f287152ef22ebb546367 100644 (file)
@@ -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 (file)
index 0000000..8d03c36
--- /dev/null
@@ -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));
+}