From: Pierre-Emmanuel Patry Date: Wed, 1 Oct 2025 14:35:37 +0000 (+0200) Subject: gccrs: Avoid malformed attribute conversion X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1461fa714b54621b6b0c0f9258dd5e15ccf4c5f9;p=thirdparty%2Fgcc.git gccrs: Avoid malformed attribute conversion Add location for malformed attribute errors and avoid processing of malformed attributes. gcc/rust/ChangeLog: * ast/rust-ast.cc (AttrInputMetaItemContainer::separate_cfg_attrs): Avoid malformed attributes. * util/rust-attributes.cc (AttributeChecker::visit): Change location. gcc/testsuite/ChangeLog: * rust/compile/attr_malformed_path.rs: New test. Signed-off-by: Pierre-Emmanuel Patry --- diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc index 003a6edbc10..a4b256c9e67 100644 --- a/gcc/rust/ast/rust-ast.cc +++ b/gcc/rust/ast/rust-ast.cc @@ -4128,6 +4128,12 @@ AttrInputMetaItemContainer::separate_cfg_attrs () const for (auto it = items.begin () + 1; it != items.end (); ++it) { + if ((*it)->get_kind () == MetaItemInner::Kind::MetaItem + && static_cast (**it).get_item_kind () + == MetaItem::ItemKind::PathExpr + && !static_cast (**it).get_expr ().is_literal ()) + continue; + Attribute attr = (*it)->to_attribute (); if (attr.is_empty ()) { diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc index 49c4282755c..ce29e59b06d 100644 --- a/gcc/rust/util/rust-attributes.cc +++ b/gcc/rust/util/rust-attributes.cc @@ -435,9 +435,9 @@ AttributeChecker::visit (AST::MetaItemPathExpr &attribute) { if (!attribute.get_expr ().is_literal ()) { - rust_error_at (attribute.get_locus (), + rust_error_at (attribute.get_expr ().get_locus (), "malformed % attribute input"); - rust_inform (attribute.get_locus (), + rust_inform (attribute.get_expr ().get_locus (), "must be of the form: %<#[path = \"file\"]%>"); } } diff --git a/gcc/testsuite/rust/compile/attr_malformed_path.rs b/gcc/testsuite/rust/compile/attr_malformed_path.rs new file mode 100644 index 00000000000..2bccf37bd79 --- /dev/null +++ b/gcc/testsuite/rust/compile/attr_malformed_path.rs @@ -0,0 +1,3 @@ +#[cfg_attr(target_arch = "x86_64", path = (target_arch = "x86", path = "x86.rs"))] +mod imp {} +// { dg-error "malformed .path. attribute input" "" { target *-*-* } .-2 }