From: Jayant Chauhan <[email protected]>

Emit a diagnostic when #[target_feature] 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#4233

gcc/rust/ChangeLog:

        * util/rust-attributes.cc (AttributeChecker::visit): Emit diagnostic.

gcc/testsuite/ChangeLog:

        * rust/compile/target_feature-malformed-4233.rs: New test.

Signed-off-by: Jayant Chauhan <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.


Commit on github: 
https://github.com/Rust-GCC/gccrs/commit/d63a4c39dc925e88fa66a5283cfa0212c933131d

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/4349

 gcc/rust/util/rust-attributes.cc                      | 11 +++++++++++
 .../rust/compile/target_feature-malformed-4233.rs     |  6 ++++++
 2 files changed, 17 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/target_feature-malformed-4233.rs

diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc
index c001ab52d..ec14744ff 100644
--- a/gcc/rust/util/rust-attributes.cc
+++ b/gcc/rust/util/rust-attributes.cc
@@ -864,6 +864,17 @@ AttributeChecker::visit (AST::Function &fun)
        {
          check_crate_type (name, attribute);
        }
+      else if (result.name == Attrs::TARGET_FEATURE)
+       {
+         if (!attribute.has_attr_input ())
+           {
+             rust_error_at (attribute.get_locus (),
+                            "malformed %<target_feature%> attribute input");
+             rust_inform (attribute.get_locus (),
+                          "must be of the form: %<#[target_feature(enable = "
+                          "\"name\")]%>");
+           }
+       }
       else if (result.name == "no_mangle")
        check_no_mangle_function (attribute, fun);
 
diff --git a/gcc/testsuite/rust/compile/target_feature-malformed-4233.rs 
b/gcc/testsuite/rust/compile/target_feature-malformed-4233.rs
new file mode 100644
index 000000000..8e8c232e3
--- /dev/null
+++ b/gcc/testsuite/rust/compile/target_feature-malformed-4233.rs
@@ -0,0 +1,6 @@
+// { dg-options "-w" }
+// Test for issue #4233 - malformed #[target_feature] attribute input
+
+#[target_feature] // { dg-error "malformed .target_feature. attribute input" }
+unsafe fn foo_sse() {} 
+// { dg-note "must be of the form" "" { target *-*-* } .-2 }

base-commit: 09ba4843b369530371487e1c84372299adecc17e
-- 
2.52.0

Reply via email to