Skip to content

util/attributes: Check that #[target_feature] is only used on unsafe …#4356

Merged
P-E-P merged 1 commit intoRust-GCC:masterfrom
Pasta-coder:fix/target-feature-unsafe-4234
Jan 15, 2026
Merged

util/attributes: Check that #[target_feature] is only used on unsafe …#4356
P-E-P merged 1 commit intoRust-GCC:masterfrom
Pasta-coder:fix/target-feature-unsafe-4234

Conversation

@Pasta-coder
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

thanks for the review .

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

@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
Copy Markdown
Contributor Author

drafted to resolve merge conflicts

@Pasta-coder Pasta-coder force-pushed the fix/target-feature-unsafe-4234 branch 5 times, most recently from 4ce4e1e to 23c54b8 Compare January 13, 2026 21:29
@Pasta-coder Pasta-coder marked this pull request as ready for review January 13, 2026 21:53
@Pasta-coder Pasta-coder force-pushed the fix/target-feature-unsafe-4234 branch 11 times, most recently from 40f8d23 to c2e0bc6 Compare January 14, 2026 12:23
@Pasta-coder
Copy link
Copy Markdown
Contributor Author

@P-E-P please review .

thankyou .

Copy link
Copy Markdown
Member

@P-E-P P-E-P left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer a clearer message in the changelog rather than simply "modified"
* util/rust-attributes.cc (AttributeChecker::visit): modified.

This part will be extracted from the commit and will lack the context. Please add what has changed. Otherwise LGTM.

…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):
	Reject #[target_feature] on non-unsafe functions.

gcc/testsuite/ChangeLog:

	* rust/compile/issue-4234.rs: New test.
	* rust/compile/unsafe11.rs: Mark function as unsafe to
	to satisfy new #[target_feature] restriction.

Signed-off-by: Jayant Chauhan <0001jayant@gmail.com>
@Pasta-coder Pasta-coder force-pushed the fix/target-feature-unsafe-4234 branch from c2e0bc6 to b18c4db Compare January 14, 2026 15:28
@Pasta-coder
Copy link
Copy Markdown
Contributor Author

@P-E-P , commit message updated .

thankyou .

@P-E-P P-E-P added this pull request to the merge queue Jan 15, 2026
Merged via the queue into Rust-GCC:master with commit 4d60acd Jan 15, 2026
12 checks passed
@Pasta-coder Pasta-coder deleted the fix/target-feature-unsafe-4234 branch January 15, 2026 18:19
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

3 participants