]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: fix error multiple cfg predicates
authorLucas Ly Ba <lucas.ly-ba@outlook.com>
Thu, 6 Nov 2025 16:53:00 +0000 (16:53 +0000)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 17 Nov 2025 14:58:18 +0000 (15:58 +0100)
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 <lucas.ly-ba@outlook.com>
gcc/rust/ast/rust-ast.cc
gcc/testsuite/rust/compile/issue-4267.rs [new file with mode: 0644]

index 337a338f9a3902b336e6dc180bd8af928ebfe518..5bced483adb47a8a0e0c7259ab397bc7a8442650 100644 (file)
@@ -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 (file)
index 0000000..f507748
--- /dev/null
@@ -0,0 +1,3 @@
+#[cfg(a,a)]
+// { dg-error "multiple .cfg. predicates are specified" "" { target *-*-* } .-1 }
+fn a(){}