https://gcc.gnu.org/g:24357b9d970b12b4e3859a383472f3a238573b8c
commit r16-6841-g24357b9d970b12b4e3859a383472f3a238573b8c Author: Jayant Chauhan <[email protected]> Date: Tue Jan 6 21:55:02 2026 +0530 gccrs: util/attributes: error on malformed #[target_feature] input 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]> Diff: --- gcc/rust/util/rust-attributes.cc | 11 +++++++++++ gcc/testsuite/rust/compile/target_feature-malformed-4233.rs | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc index c001ab52d860..ec14744fff49 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 000000000000..8e8c232e3d17 --- /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 }
