]> 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)
committerP-E-P <32375388+P-E-P@users.noreply.github.com>
Mon, 19 May 2025 09:42:09 +0000 (09:42 +0000)
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 73d71ca185a2bc26332481d984cf96174ac38b07..1dc63f417e2c4fd03d1d1dc926c857c48717d9a3 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));
+}