From: Matthew Jasper Date: Sun, 21 May 2023 19:23:27 +0000 (+0100) Subject: gccrs: Only check first item of cfg_attr attribute as predicate X-Git-Tag: basepoints/gcc-15~2527 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7e96bfe42867757c35069f2c18abc92c41af0e6b;p=thirdparty%2Fgcc.git gccrs: Only check first item of cfg_attr attribute as predicate 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 --- diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc index 55b21d3e8401..d2550b08607d 100644 --- a/gcc/rust/ast/rust-ast.cc +++ b/gcc/rust/ast/rust-ast.cc @@ -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 (*attr_input); + return meta_item.get_items ().front ()->check_cfg_predicate (session); } std::vector diff --git a/gcc/testsuite/rust/compile/cfg-attr.rs b/gcc/testsuite/rust/compile/cfg-attr.rs new file mode 100644 index 000000000000..137ed2c7adb5 --- /dev/null +++ b/gcc/testsuite/rust/compile/cfg-attr.rs @@ -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() { }