Skip to content

Commit a23fc2e

Browse files
committed
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]>
1 parent 7699f7f commit a23fc2e

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

gcc/rust/hir/rust-ast-lower-base.cc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -820,9 +820,17 @@ void
820820
ASTLoweringBase::handle_doc_item_attribute (const ItemWrapper &,
821821
const AST::Attribute &attr)
822822
{
823-
auto simple_doc_comment = attr.has_attr_input ()
824-
&& attr.get_attr_input ().get_attr_input_type ()
825-
== AST::AttrInput::AttrInputType::LITERAL;
823+
if (!attr.has_attr_input ())
824+
{
825+
rust_error_at (attr.get_locus (),
826+
"attribute must be of the form %qs or %qs",
827+
"#[doc(hidden|inline|...)]", "#[doc = string]");
828+
return;
829+
}
830+
831+
auto simple_doc_comment = attr.get_attr_input ().get_attr_input_type ()
832+
== AST::AttrInput::AttrInputType::LITERAL;
833+
826834
if (simple_doc_comment)
827835
return;
828836

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#[doc]
2+
// { dg-error "attribute must be of the form ...doc.hidden.inline....... or ...doc = string.." "" { target *-*-* } .-1 }
3+
pub fn a(){}

0 commit comments

Comments
 (0)