https://gcc.gnu.org/g:7dc139172ea3a9e5b4976049933136b1b9e5be98

commit r16-5346-g7dc139172ea3a9e5b4976049933136b1b9e5be98
Author: Lucas Ly Ba <[email protected]>
Date:   Thu Nov 6 16:53:00 2025 +0000

    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 <[email protected]>

Diff:
---
 gcc/rust/ast/rust-ast.cc                 | 8 ++++++++
 gcc/testsuite/rust/compile/issue-4267.rs | 3 +++
 2 files changed, 11 insertions(+)

diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index 337a338f9a39..5bced483adb4 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 %<cfg_attr%> 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 000000000000..f507748c6944
--- /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(){}

Reply via email to