From: Pierre-Emmanuel Patry <[email protected]>
gcc/rust/ChangeLog:
* ast/rust-ast.cc (Attribute::check_cfg_predicate): Emit an error with
empty cfg_attr input.
gcc/testsuite/ChangeLog:
* rust/compile/issue-3966.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
---
gcc/rust/ast/rust-ast.cc | 12 ++++++++++--
gcc/testsuite/rust/compile/issue-3966.rs | 5 +++++
2 files changed, 15 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/issue-3966.rs
diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index 7feb7a688f7..8072ce96b4f 100644
--- a/gcc/rust/ast/rust-ast.cc
+++ b/gcc/rust/ast/rust-ast.cc
@@ -4165,11 +4165,12 @@ AttrInputMetaItemContainer::separate_cfg_attrs () const
bool
Attribute::check_cfg_predicate (const Session &session) const
{
+ auto string_path = path.as_string ();
/* assume that cfg predicate actually can exist, i.e. attribute has cfg or
* cfg_attr path */
if (!has_attr_input ()
- || (path.as_string () != Values::Attributes::CFG
- && path.as_string () != Values::Attributes::CFG_ATTR))
+ || (string_path != Values::Attributes::CFG
+ && string_path != Values::Attributes::CFG_ATTR))
{
// DEBUG message
rust_debug (
@@ -4185,6 +4186,13 @@ Attribute::check_cfg_predicate (const Session &session)
const
return false;
auto &meta_item = static_cast<AttrInputMetaItemContainer &> (*attr_input);
+ if (meta_item.get_items ().empty ()
+ && string_path == Values::Attributes::CFG_ATTR)
+ {
+ rust_error_at (path.get_locus (),
+ "malformed %<cfg_attr%> attribute input");
+ return false;
+ }
return meta_item.get_items ().front ()->check_cfg_predicate (session);
}
diff --git a/gcc/testsuite/rust/compile/issue-3966.rs
b/gcc/testsuite/rust/compile/issue-3966.rs
new file mode 100644
index 00000000000..20d3031efa4
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3966.rs
@@ -0,0 +1,5 @@
+struct S {
+ #[cfg_attr()]
+ field: u8,
+ // { dg-error "malformed .cfg_attr. attribute input" "" { target *-*-* }
.-2 }
+}
--
2.50.1