Skip to content

Commit d4d1fc1

Browse files
lucasly-baphilberty
authored andcommitted
gccrs: fix segfault with empty cfg attribute
gcc/rust/ChangeLog: * ast/rust-ast.cc (Attribute::check_cfg_predicate): add cfg path in condition gcc/testsuite/ChangeLog: * rust/compile/issue-4261.rs: New test. Signed-off-by: Lucas Ly Ba <lucas.ly-ba@outlook.com>
1 parent 486d641 commit d4d1fc1

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

gcc/rust/ast/rust-ast.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4179,10 +4179,11 @@ Attribute::check_cfg_predicate (const Session &session) const
41794179

41804180
auto &meta_item = static_cast<AttrInputMetaItemContainer &> (*attr_input);
41814181
if (meta_item.get_items ().empty ()
4182-
&& string_path == Values::Attributes::CFG_ATTR)
4182+
&& (string_path == Values::Attributes::CFG
4183+
|| string_path == Values::Attributes::CFG_ATTR))
41834184
{
4184-
rust_error_at (path.get_locus (),
4185-
"malformed %<cfg_attr%> attribute input");
4185+
rust_error_at (path.get_locus (), "malformed %<%s%> attribute input",
4186+
string_path.c_str ());
41864187
return false;
41874188
}
41884189

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#[cfg()]
2+
// { dg-error "malformed .cfg. attribute input" "" { target *-*-* } .-1 }
3+
fn a() {}

0 commit comments

Comments
 (0)