Merge common attribute handling code between Rust and c-family. #241

Closed
imperio wants to merge 1 commit from imperio/gcc:rust-common-attrs into trunk
Member

Follow-up of #207.

It merges common code for attributes handling between the Rust front-end and attr-handlers.c. I renamed some functions by prepending them with rust_ when it was also functions present in attr-handlers.h.

CC: gcc-rust@gcc.gnu.org @cohenarthur

Follow-up of https://forge.sourceware.org/gcc/gcc/pulls/207. It merges common code for attributes handling between the Rust front-end and `attr-handlers.c`. I renamed some functions by prepending them with `rust_` when it was also functions present in `attr-handlers.h`. CC: gcc-rust@gcc.gnu.org @cohenarthur
Member

Hi @imperio. This bot helps send your PR as a patch series to the mailing list.

Next steps

  1. Write a clear PR description. It will be used as the cover letter.
  2. To CC extra people, add lines like this at the end of the PR description: CC: Reviewer1 <revi.ewer@example.com>, Reviewer2 <an.other@example.com>.
  3. To preview the emails, comment with /preview.
  4. When ready, request review in the Reviewers section. Or, if you just want to send the series, comment with /submit.
  5. Use the cover-letter links below to follow replies.
  6. For a new patch series, push your changes, update the PR description with a Changes since vX section, and comment with /submit again.

See Submitting Patches and UsingForge.

Consider joining the gcc and gcc-patches mailing lists..
For real time communication, check the gcc irc channels.

Or join #overseers on Libera Chat, particularly if this automation is not working (stay online to get replies, IRC does not save messages if people are not online).

<!-- pr-welcome --> Hi @imperio. This bot helps send your PR as a patch series to the mailing list. ## Next steps 1. Write a clear PR description. It will be used as the cover letter. 2. To CC extra people, add lines like this **at the end** of the PR description: `CC: Reviewer1 <revi.ewer@example.com>, Reviewer2 <an.other@example.com>`. 3. To preview the emails, comment with `/preview`. 4. When ready, request review in the Reviewers section. Or, if you just want to send the series, comment with `/submit`. 5. Use the cover-letter links below to follow replies. 6. For a new patch series, push your changes, update the PR description with a `Changes since vX` section, and comment with `/submit` again. See [Submitting Patches](https://gcc.gnu.org/contribute.html#patches) and [UsingForge](https://gcc.gnu.org/wiki/UsingForge). Consider joining the [gcc and gcc-patches mailing lists.](https://gcc.gnu.org/lists.html). For real time communication, check the [gcc irc channels](https://gcc.gnu.org/wiki/GCConIRC). Or join [`#overseers`](https://web.libera.chat/#overseers) on Libera Chat, particularly if this automation is not working (stay online to get replies, IRC does not save messages if people are not online).
imperio force-pushed rust-common-attrs from fda2955be4
Some checks failed
/ format-checks (pull_request) Failing after 1m19s
to d0e4c6d117
Some checks failed
/ format-checks (pull_request) Failing after 1m19s
2026-10-06 15:12:04 +00:00
Compare
Author
Member

/submit

/submit
Member
Cannot post as:
<!-- pr-not-posted -->Cannot post as: - gcc-rust@gcc.gnu.org @cohenarthur is not a valid email address
cohenarthur requested changes 2026-10-06 21:29:45 +00:00
Dismissed
cohenarthur left a comment

The changes look good to me but the formatting seems off per our clang-format? Here is the diff when I autoformat the file. If you want to just apply that, then I'm happy to merge the changes :) Thank you!!

diff --git a/gcc/rust/rust-attribs.cc b/gcc/rust/rust-attribs.cc
index ec135df1967..a6ae3f34a46 100644
--- a/gcc/rust/rust-attribs.cc
+++ b/gcc/rust/rust-attribs.cc
@@ -107,15 +107,14 @@ static const attribute_spec grs_langhook_common_attributes[] = {
   ATTR_SPEC ("leaf", 0, 0, true, false, false, false,
             rust_handle_leaf_attribute, NULL),
   ATTR_SPEC ("const", 0, 0, true, false, false, false,
-            rust_handle_const_attribute,
-            rust_attr_const_pure_exclusions),
+            rust_handle_const_attribute, rust_attr_const_pure_exclusions),
   ATTR_SPEC ("malloc", 0, 0, true, false, false, false, handle_malloc_attribute,
             NULL),
   ATTR_SPEC ("returns_twice", 0, 0, true, false, false, false,
-            rust_handle_returns_twice_attribute, attr_returns_twice_exclusions),
+            rust_handle_returns_twice_attribute,
+            attr_returns_twice_exclusions),
   ATTR_SPEC ("pure", 0, 0, true, false, false, false,
-            rust_handle_pure_attribute,
-            rust_attr_const_pure_exclusions),
+            rust_handle_pure_attribute, rust_attr_const_pure_exclusions),
   ATTR_SPEC ("nonnull", 0, -1, false, true, true, false,
             handle_nonnull_attribute, NULL),
   ATTR_SPEC ("nothrow", 0, 0, true, false, false, false,
@@ -354,7 +353,7 @@ handle_transaction_pure_attribute (tree *node, tree, tree, int, bool *)

 static tree
 rust_handle_returns_twice_attribute (tree *node, tree name, tree, int,
-                                   bool *no_add_attrs)
+                                    bool *no_add_attrs)
 {
   if (TREE_CODE (*node) != FUNCTION_DECL)
     {
The changes look good to me but the formatting seems off per our clang-format? Here is the diff when I autoformat the file. If you want to just apply that, then I'm happy to merge the changes :) Thank you!! ```diff diff --git a/gcc/rust/rust-attribs.cc b/gcc/rust/rust-attribs.cc index ec135df1967..a6ae3f34a46 100644 --- a/gcc/rust/rust-attribs.cc +++ b/gcc/rust/rust-attribs.cc @@ -107,15 +107,14 @@ static const attribute_spec grs_langhook_common_attributes[] = { ATTR_SPEC ("leaf", 0, 0, true, false, false, false, rust_handle_leaf_attribute, NULL), ATTR_SPEC ("const", 0, 0, true, false, false, false, - rust_handle_const_attribute, - rust_attr_const_pure_exclusions), + rust_handle_const_attribute, rust_attr_const_pure_exclusions), ATTR_SPEC ("malloc", 0, 0, true, false, false, false, handle_malloc_attribute, NULL), ATTR_SPEC ("returns_twice", 0, 0, true, false, false, false, - rust_handle_returns_twice_attribute, attr_returns_twice_exclusions), + rust_handle_returns_twice_attribute, + attr_returns_twice_exclusions), ATTR_SPEC ("pure", 0, 0, true, false, false, false, - rust_handle_pure_attribute, - rust_attr_const_pure_exclusions), + rust_handle_pure_attribute, rust_attr_const_pure_exclusions), ATTR_SPEC ("nonnull", 0, -1, false, true, true, false, handle_nonnull_attribute, NULL), ATTR_SPEC ("nothrow", 0, 0, true, false, false, false, @@ -354,7 +353,7 @@ handle_transaction_pure_attribute (tree *node, tree, tree, int, bool *) static tree rust_handle_returns_twice_attribute (tree *node, tree name, tree, int, - bool *no_add_attrs) + bool *no_add_attrs) { if (TREE_CODE (*node) != FUNCTION_DECL) { ```
cohenarthur left a comment

The forge is not showing the update but this was fixed by @imperio on his branch - I'm going to test it and merge to trunk. Thank you for your work @imperio!

The forge is not showing the update but this was fixed by @imperio on his branch - I'm going to test it and merge to trunk. Thank you for your work @imperio!
Author
Member

@cohenarthur approved it so it was merged as commit ef6cd7cfcf.

@cohenarthur approved it so it was merged as commit https://forge.sourceware.org/gcc/gcc/commit/ef6cd7cfcfb90cae077c1018fe1ef51e64d02aac.
imperio closed this pull request 2026-10-07 12:02:43 +00:00
Member
Cannot publish to mailing list as:
<!-- pr-not-posted -->Cannot publish to mailing list as: - gcc-rust@gcc.gnu.org @cohenarthur is not a valid email address
Member
Cannot publish to mailing list as:
<!-- pr-not-posted -->Cannot publish to mailing list as: - gcc-rust@gcc.gnu.org @cohenarthur is not a valid email address
Some checks failed
/ format-checks (pull_request) Failing after 1m19s

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gcc/gcc!241
No description provided.