]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Only check first item of cfg_attr attribute as predicate
authorMatthew Jasper <mjjasper1@gmail.com>
Sun, 21 May 2023 19:23:27 +0000 (20:23 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:37:21 +0000 (18:37 +0100)
In #[cfg_attr(A, B, C(D))], only A is a predicate.

gcc/rust/ChangeLog:

* ast/rust-ast.cc (Attribute::check_cfg_predicate):
Only check first item as a predicate.

gcc/testsuite/ChangeLog:

* rust/compile/cfg-attr.rs: New test.

Signed-off-by: Matthew Jasper <mjjasper1@gmail.com>
gcc/rust/ast/rust-ast.cc
gcc/testsuite/rust/compile/cfg-attr.rs [new file with mode: 0644]

index 55b21d3e8401fc56984a252ef3ff87038f03bfae..d2550b08607d9458f66dde722ff017ba847aac32 100644 (file)
@@ -4183,7 +4183,8 @@ Attribute::check_cfg_predicate (const Session &session) const
   if (!is_parsed_to_meta_item ())
     return false;
 
-  return attr_input->check_cfg_predicate (session);
+  auto &meta_item = static_cast<AttrInputMetaItemContainer &> (*attr_input);
+  return meta_item.get_items ().front ()->check_cfg_predicate (session);
 }
 
 std::vector<Attribute>
diff --git a/gcc/testsuite/rust/compile/cfg-attr.rs b/gcc/testsuite/rust/compile/cfg-attr.rs
new file mode 100644 (file)
index 0000000..137ed2c
--- /dev/null
@@ -0,0 +1,7 @@
+// { dg-additional-options "-w -frust-cfg=A" }
+#![cfg_attr(not(B), allow(dead_code))]
+#![cfg_attr(A, allow(while_true))]
+
+#[cfg_attr(not(B), allow(deprecated))]
+#[cfg_attr(A, allow(drop_bounds))]
+fn main() { }