From: Jayant Chauhan <0001jayant@gmail.com> Date: Tue, 6 Jan 2026 18:12:58 +0000 (+0530) Subject: gccrs: util/attributes: error on malformed #[no_mangle] input X-Git-Tag: basepoints/gcc-17~1962 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bf834bda455959a36323f98edefc59bfdfe1499e;p=thirdparty%2Fgcc.git gccrs: util/attributes: error on malformed #[no_mangle] input Emit a diagnostic when #[no_mangle] is used with arguments, matching rustc behavior. The no_mangle attribute is a word attribute and should not accept any input values. Fixes Rust-GCC#4230 gcc/rust/ChangeLog: * util/rust-attributes.cc (AttributeChecker::visit): Emit diagnostic. gcc/testsuite/ChangeLog: * rust/compile/no_mangle-malformed.rs: New test. Signed-off-by: Jayant Chauhan <0001jayant@gmail.com> --- diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc index ec14744fff4..57fad8c2a58 100644 --- a/gcc/rust/util/rust-attributes.cc +++ b/gcc/rust/util/rust-attributes.cc @@ -464,7 +464,6 @@ AttributeChecker::check_attribute (const AST::Attribute &attribute) else if (result.name == Attrs::DEPRECATED) check_deprecated_attribute (attribute); } - void AttributeChecker::check_attributes (const AST::AttrVec &attributes) { @@ -876,8 +875,17 @@ AttributeChecker::visit (AST::Function &fun) } } else if (result.name == "no_mangle") - check_no_mangle_function (attribute, fun); - + { + if (attribute.has_attr_input ()) + { + rust_error_at (attribute.get_locus (), + "malformed % attribute input"); + rust_inform (attribute.get_locus (), + "must be of the form: %<#[no_mangle]%>"); + } + else + check_no_mangle_function (attribute, fun); + } else if (result.name == Attrs::LINK_NAME) { if (!attribute.has_attr_input ()) diff --git a/gcc/testsuite/rust/compile/no_mangle-malformed.rs b/gcc/testsuite/rust/compile/no_mangle-malformed.rs new file mode 100644 index 00000000000..5e73d5778fe --- /dev/null +++ b/gcc/testsuite/rust/compile/no_mangle-malformed.rs @@ -0,0 +1,4 @@ +// { dg-options "-w" } +#[no_mangle(foo)] // { dg-error "malformed .no_mangle. attribute input" } +fn foo() {} +// { dg-note "must be of the form" "" { target *-*-* } .-2 }