Skip to content

Commit c4d2abe

Browse files
Pasta-coderP-E-P
authored andcommitted
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 #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]>
1 parent 5103d5d commit c4d2abe

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

gcc/rust/util/rust-attributes.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,17 @@ AttributeChecker::visit (AST::Function &fun)
866866
}
867867
else if (result.name == "no_mangle")
868868
check_no_mangle_function (attribute, fun);
869+
870+
else if (result.name == Attrs::LINK_NAME)
871+
{
872+
if (!attribute.has_attr_input ())
873+
{
874+
rust_error_at (attribute.get_locus (),
875+
"malformed %<link_name%> attribute input");
876+
rust_inform (attribute.get_locus (),
877+
"must be of the form: %<#[link_name = \"name\"]%>");
878+
}
879+
}
869880
}
870881
if (fun.has_body ())
871882
fun.get_definition ().value ()->accept_vis (*this);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// { dg-options "-w" }
2+
#[link_name] // { dg-error "malformed .link_name. attribute input" }
3+
fn foo() {}
4+
5+
// { dg-note "must be of the form" "" { target *-*-* } .-3 }

0 commit comments

Comments
 (0)