Skip to content

Conversation

@Pasta-coder
Copy link
Contributor

The #[target_feature] attribute allows code generation that may not be supported by the runtime hardware, making it inherently unsafe. This patch adds a check to ensure it is only applied to functions declared as 'unsafe', matching rustc behavior (E0658).

Fixes #4234

gcc/rust/ChangeLog:

* util/rust-attributes.cc: Error if target_feature is on safe function.

gcc/testsuite/ChangeLog:

* rust/compile/target_feature-unsafe.rs: New test.

@Pasta-coder Pasta-coder force-pushed the fix/target-feature-unsafe-4234 branch 3 times, most recently from 6e8d514 to 3285e5d Compare January 5, 2026 08:27
@dkm
Copy link
Member

dkm commented Jan 6, 2026

Thanks for your contribution!

A bit similar as my other comment in your other PR, can you be more precise in the changelog and clearly identify which member you have modifying?

AttributeChecker::visit (AST::Function &fun)

?
Thanks

@Pasta-coder
Copy link
Contributor Author

thanks for the review .

will change all the commit messages to be more precise in the changelog.

…functions

The #[target_feature] attribute allows code generation that may not be
supported by the runtime hardware, making it inherently unsafe.
This patch adds a check to ensure it is only applied to functions declared
as 'unsafe', matching rustc behavior (E0658).

Fixes Rust-GCC#4234

gcc/rust/ChangeLog:

	* util/rust-attributes.cc: (AttributeChecker::visit): Error if target_feature
	is on safe function.

gcc/testsuite/ChangeLog:

	* rust/compile/target_feature-unsafe.rs: New test.
	* rust/compile/unsafe11.rs: Mark function as unsafe to satisfy new check.

Signed-off-by: Jayant Chauhan <[email protected]>
@Pasta-coder Pasta-coder force-pushed the fix/target-feature-unsafe-4234 branch from 3285e5d to 212d55f Compare January 6, 2026 12:59
@Pasta-coder Pasta-coder marked this pull request as draft January 6, 2026 13:29
@Pasta-coder
Copy link
Contributor Author

drafted to resolve merge conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

target_feature attribute should only be applied to unsafe functions

2 participants