]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: util/attributes: error on malformed #[link_name] input
authorJayant Chauhan <0001jayant@gmail.com>
Sat, 3 Jan 2026 23:36:53 +0000 (05:06 +0530)
committerArthur Cohen <arthur.cohen@embecosm.com>
Fri, 16 Jan 2026 16:32:07 +0000 (17:32 +0100)
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 <0001jayant@gmail.com>
gcc/rust/util/rust-attributes.cc
gcc/testsuite/rust/compile/link_name-malformed.rs [new file with mode: 0644]

index 0ecdb92c7b5b681051d93c7ee2c902bbe9e81ca1..c001ab52d860c8797e215eec6028820e7e1b2b56 100644 (file)
@@ -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 (file)
index 0000000..e09ec8b
--- /dev/null
@@ -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 }