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]>
---
 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 c001ab52d86..ec14744fff4 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 00000000000..8e8c232e3d1
--- /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 }
-- 
2.50.1

Reply via email to