From 7dc139172ea3a9e5b4976049933136b1b9e5be98 Mon Sep 17 00:00:00 2001 From: Lucas Ly Ba Date: Thu, 6 Nov 2025 16:53:00 +0000 Subject: [PATCH] gccrs: fix error multiple cfg predicates gcc/rust/ChangeLog: * ast/rust-ast.cc (Attribute::check_cfg_predicate): Make error. gcc/testsuite/ChangeLog: * rust/compile/issue-4267.rs: New test. Signed-off-by: Lucas Ly Ba --- gcc/rust/ast/rust-ast.cc | 8 ++++++++ gcc/testsuite/rust/compile/issue-4267.rs | 3 +++ 2 files changed, 11 insertions(+) create mode 100644 gcc/testsuite/rust/compile/issue-4267.rs diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc index 337a338f9a3..5bced483adb 100644 --- a/gcc/rust/ast/rust-ast.cc +++ b/gcc/rust/ast/rust-ast.cc @@ -4185,6 +4185,14 @@ Attribute::check_cfg_predicate (const Session &session) const "malformed % attribute input"); return false; } + + if (string_path == Values::Attributes::CFG + && meta_item.get_items ().size () != 1) + { + rust_error_at (path.get_locus (), "multiple %qs predicates are specified", + path.as_string ().c_str ()); + return false; + } return meta_item.get_items ().front ()->check_cfg_predicate (session); } diff --git a/gcc/testsuite/rust/compile/issue-4267.rs b/gcc/testsuite/rust/compile/issue-4267.rs new file mode 100644 index 00000000000..f507748c694 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-4267.rs @@ -0,0 +1,3 @@ +#[cfg(a,a)] +// { dg-error "multiple .cfg. predicates are specified" "" { target *-*-* } .-1 } +fn a(){} -- 2.47.3