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

commit r16-5600-gad7717b994732d0de46c506d96f2f569f0b65866
Author: Lucas Ly Ba <[email protected]>
Date:   Fri Nov 7 16:38:46 2025 +0000

    gccrs: fix segfault on empty doc attribute
    
    gcc/rust/ChangeLog:
    
            * hir/rust-ast-lower-base.cc 
(ASTLoweringBase::handle_doc_item_attribute): Make error.
    
    gcc/testsuite/ChangeLog:
    
            * rust/compile/issue-4226.rs: New test.
    
    Signed-off-by: Lucas Ly Ba <[email protected]>

Diff:
---
 gcc/rust/hir/rust-ast-lower-base.cc      | 14 +++++++++++---
 gcc/testsuite/rust/compile/issue-4226.rs |  3 +++
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/gcc/rust/hir/rust-ast-lower-base.cc 
b/gcc/rust/hir/rust-ast-lower-base.cc
index 1c8e5b6d2c0e..8984c98daaac 100644
--- a/gcc/rust/hir/rust-ast-lower-base.cc
+++ b/gcc/rust/hir/rust-ast-lower-base.cc
@@ -820,9 +820,17 @@ void
 ASTLoweringBase::handle_doc_item_attribute (const ItemWrapper &,
                                            const AST::Attribute &attr)
 {
-  auto simple_doc_comment = attr.has_attr_input ()
-                           && attr.get_attr_input ().get_attr_input_type ()
-                                == AST::AttrInput::AttrInputType::LITERAL;
+  if (!attr.has_attr_input ())
+    {
+      rust_error_at (attr.get_locus (),
+                    "attribute must be of the form %qs or %qs",
+                    "#[doc(hidden|inline|...)]", "#[doc = string]");
+      return;
+    }
+
+  auto simple_doc_comment = attr.get_attr_input ().get_attr_input_type ()
+                           == AST::AttrInput::AttrInputType::LITERAL;
+
   if (simple_doc_comment)
     return;
 
diff --git a/gcc/testsuite/rust/compile/issue-4226.rs 
b/gcc/testsuite/rust/compile/issue-4226.rs
new file mode 100644
index 000000000000..553faf291f46
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-4226.rs
@@ -0,0 +1,3 @@
+#[doc]
+// { dg-error "attribute must be of the form ...doc.hidden.inline....... or 
...doc = string.." "" { target *-*-* } .-1 }
+pub fn a(){}

Reply via email to