https://gcc.gnu.org/g:6ff1a62209a1e62665af9b8013d19bde7fe3c226
commit r16-5597-g6ff1a62209a1e62665af9b8013d19bde7fe3c226 Author: Lucas Ly Ba <[email protected]> Date: Thu Nov 6 15:37:52 2025 +0000 gccrs: fix cfg attribute without parentheses error gcc/rust/ChangeLog: * ast/rust-ast.cc (Attribute::check_cfg_predicate): Make error when attribute has no input. gcc/testsuite/ChangeLog: * rust/compile/issue-4262.rs: New test. Signed-off-by: Lucas Ly Ba <[email protected]> Diff: --- gcc/rust/ast/rust-ast.cc | 16 ++++------------ gcc/testsuite/rust/compile/issue-4262.rs | 3 +++ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc index f3ad2fe5da05..d8713071c4c3 100644 --- a/gcc/rust/ast/rust-ast.cc +++ b/gcc/rust/ast/rust-ast.cc @@ -4163,16 +4163,10 @@ 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 () - || (string_path != Values::Attributes::CFG - && string_path != Values::Attributes::CFG_ATTR)) + if (!has_attr_input ()) { - // DEBUG message - rust_debug ( - "tried to check cfg predicate on attr that either has no input " - "or invalid path. attr: '%s'", - as_string ().c_str ()); - + rust_error_at (path.get_locus (), "%qs is not followed by parentheses", + string_path.c_str ()); return false; } @@ -4181,9 +4175,7 @@ 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 - || string_path == Values::Attributes::CFG_ATTR)) + if (meta_item.get_items ().empty ()) { rust_error_at (path.get_locus (), "malformed %<%s%> attribute input", string_path.c_str ()); diff --git a/gcc/testsuite/rust/compile/issue-4262.rs b/gcc/testsuite/rust/compile/issue-4262.rs new file mode 100644 index 000000000000..2ce1cb49afae --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-4262.rs @@ -0,0 +1,3 @@ +#[cfg] +// { dg-error ".cfg. is not followed by parentheses" "" { target *-*-* } .-1 } +fn a() {}
