Skip to content

Commit 94d27fb

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 <lucas.ly-ba@outlook.com>
1 parent 7699f7f commit 94d27fb

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -820,9 +820,18 @@ 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+
// FIXME: attr_input must be a string
826+
rust_error_at (attr.get_locus (),
827+
"attribute must be of the form %qs or %qs",
828+
"#[doc(hidden|inline|...)]", "#[doc = string]");
829+
return;
830+
}
831+
832+
auto simple_doc_comment = attr.get_attr_input ().get_attr_input_type ()
833+
== AST::AttrInput::AttrInputType::LITERAL;
834+
826835
if (simple_doc_comment)
827836
return;
828837

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)