https://gcc.gnu.org/g:0a908938b4578b936d035281c442820b45e22bae
commit r16-6839-g0a908938b4578b936d035281c442820b45e22bae Author: Jayant Chauhan <[email protected]> Date: Sun Jan 4 05:06:53 2026 +0530 gccrs: util/attributes: error on malformed #[link_name] input Emit a diagnostic when #[link_name] is used without arguments, matching rustc behavior. This prevents silent acceptance of empty attributes and provides a helpful diagnostic that shows the expected form. Fixes Rust-GCC#4228 gcc/rust/ChangeLog: * util/rust-attributes.cc: Emit diagnostic. gcc/testsuite/ChangeLog: * rust/compile/link_name-malformed.rs: New test. Signed-off-by: Jayant Chauhan <[email protected]> Diff: --- gcc/rust/util/rust-attributes.cc | 11 +++++++++++ gcc/testsuite/rust/compile/link_name-malformed.rs | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc index 0ecdb92c7b5b..c001ab52d860 100644 --- a/gcc/rust/util/rust-attributes.cc +++ b/gcc/rust/util/rust-attributes.cc @@ -866,6 +866,17 @@ AttributeChecker::visit (AST::Function &fun) } else if (result.name == "no_mangle") check_no_mangle_function (attribute, fun); + + else if (result.name == Attrs::LINK_NAME) + { + if (!attribute.has_attr_input ()) + { + rust_error_at (attribute.get_locus (), + "malformed %<link_name%> attribute input"); + rust_inform (attribute.get_locus (), + "must be of the form: %<#[link_name = \"name\"]%>"); + } + } } if (fun.has_body ()) fun.get_definition ().value ()->accept_vis (*this); diff --git a/gcc/testsuite/rust/compile/link_name-malformed.rs b/gcc/testsuite/rust/compile/link_name-malformed.rs new file mode 100644 index 000000000000..e09ec8b4b524 --- /dev/null +++ b/gcc/testsuite/rust/compile/link_name-malformed.rs @@ -0,0 +1,5 @@ +// { dg-options "-w" } +#[link_name] // { dg-error "malformed .link_name. attribute input" } +fn foo() {} + +// { dg-note "must be of the form" "" { target *-*-* } .-3 }
