Merge common attribute handling code between libgccjit and gcc/c-family #207

Closed
imperio wants to merge 1 commit from imperio:attr-dedup into trunk
Member

This is my third attempt at removing duplicated code between libgccjit and gcc/c-family and it seems like I was able to make it work with the help of @antoyo for the Makefile files in particular.

So this is what I did: moving code from gcc/c-family.cc into gcc/attr-handlers.cc, then I remove the duplicated code in jit/dummy-frontend.cc. There is one exception though: since libgccjit implementation of the malloc attribute is a sub-part of the gcc/c-family.cc implementation, I created a new handle_malloc_common function which is called directly by libgccjit and called under a specific condition in gcc/c-family.cc.

There are still duplicated code attributes remaining in libgccjit, but the patch is already big enough as it is so I stopped at this point.

CC: David Malcolm dmalcolm@redhat.com, josmyers@redhat.com, jit@gcc.gnu.org

This is my third attempt at removing duplicated code between `libgccjit` and `gcc/c-family` and it seems like I was able to make it work with the help of @antoyo for the Makefile files in particular. So this is what I did: moving code from `gcc/c-family.cc` into `gcc/attr-handlers.cc`, then I remove the duplicated code in `jit/dummy-frontend.cc`. There is one exception though: since libgccjit implementation of the `malloc` attribute is a sub-part of the `gcc/c-family.cc` implementation, I created a new `handle_malloc_common` function which is called directly by libgccjit and called under a specific condition in `gcc/c-family.cc`. There are still duplicated code attributes remaining in libgccjit, but the patch is already big enough as it is so I stopped at this point. CC: David Malcolm <dmalcolm@redhat.com>, <josmyers@redhat.com>, <jit@gcc.gnu.org>
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 attr-dedup from 16473cc8e3
Some checks failed
/ format-checks (pull_request) Failing after 1m35s
to 16abbee76a
Some checks failed
/ format-checks (pull_request) Failing after 1m35s
2026-07-30 15:52:09 +00:00
Compare
imperio force-pushed attr-dedup from 16abbee76a
Some checks failed
/ format-checks (pull_request) Failing after 1m35s
to 9e8128eca8
Some checks failed
/ format-checks (pull_request) Failing after 1m34s
2026-07-30 15:58:00 +00:00
Compare
imperio force-pushed attr-dedup from 9e8128eca8
Some checks failed
/ format-checks (pull_request) Failing after 1m34s
to e4440d96eb
All checks were successful
/ format-checks (pull_request) Successful in 1m34s
2026-07-30 16:00:59 +00:00
Compare
Author
Member

Finally fixed formatting (from old code mostly ^^').

Finally fixed formatting (from old code mostly ^^').
imperio force-pushed attr-dedup from e4440d96eb
All checks were successful
/ format-checks (pull_request) Successful in 1m34s
to e6819e42a6
All checks were successful
/ format-checks (pull_request) Successful in 1m32s
2026-07-30 16:12:01 +00:00
Compare
imperio force-pushed attr-dedup from e6819e42a6
All checks were successful
/ format-checks (pull_request) Successful in 1m32s
to a9a4bb0893
All checks were successful
/ format-checks (pull_request) Successful in 1m29s
2026-07-30 19:37:10 +00:00
Compare
Author
Member

/preview

/preview
Member

Sent patch series version 1 containing 1 patches to @imperio's email address.
Message Id of cover message is <bmm.hkwr5r5oqi.gcc.gcc.imperio.207.1.0@forge-stage.sourceware.org>.

Sent patch series version 1 containing 1 patches to @imperio's email address. Message Id of cover message is `<bmm.hkwr5r5oqi.gcc.gcc.imperio.207.1.0@forge-stage.sourceware.org>`.
Author
Member

/submit

/submit
Member

Version 1 of this pull request has been stored. It includes the following commits:

  • Merge common attribute handling code between libgccjit and c-family. - a9a4bb0893
<!-- pr-new-version --> Version 1 of this pull request has been stored. It includes the following commits: - Merge common attribute handling code between libgccjit and c-family. - a9a4bb08931f95489f64af2a505a8dda432a8b71
Member

Sent patch series version 1 containing 1 patches to gcc-patches mailing list gcc-patches@gcc.gnu.org and cc'd David Malcolm dmalcolm@redhat.com, josmyers@redhat.com, jit@gcc.gnu.org.
Cover letter

Sent patch series version 1 containing 1 patches to gcc-patches mailing list <gcc-patches@gcc.gnu.org> and cc'd David Malcolm <dmalcolm@redhat.com>, <josmyers@redhat.com>, <jit@gcc.gnu.org>. [Cover letter](https://inbox.sourceware.org/gcc-patches/bmm.hl02ewfvoa.gcc.gcc.imperio.207.1.0@forge-stage.sourceware.org)
Member

The overall idea looks good to me from a libgccjit maintainer point-of-view, though I didn't painstakingly check every hunk of the move.

@jsm28 : what do you think from a C maintainer/global review POV?

The overall idea looks good to me from a libgccjit maintainer point-of-view, though I didn't painstakingly check every hunk of the move. @jsm28 : what do you think from a C maintainer/global review POV?
Author
Member

ping @jsm28

ping @jsm28
Owner

The principle seems fine but the forge doesn't provide an obvious way to compare the moved code (the old version of c-attribs.cc with the new attr-handlers.cc file), and since CI is reporting conflicts with c-attribs.cc, clearly this pull request would need updating including updating the moved copy of any moved code that has changed in c-attribs.cc since work on this pull request started.

The principle seems fine but the forge doesn't provide an obvious way to compare the moved code (the old version of c-attribs.cc with the new attr-handlers.cc file), and since CI is reporting conflicts with c-attribs.cc, clearly this pull request would need updating including updating the moved copy of any moved code that has changed in c-attribs.cc since work on this pull request started.
Author
Member

I'll take that as you globally approving the patch. Considering that it moves a lot of code around, it's very prone to bitrot. I'm fixing the merge conflict, but if another merge conflict happens before next review, I'll just wait for you to review the broken state as it's time consuming to keep up.

I'll take that as you globally approving the patch. Considering that it moves a lot of code around, it's very prone to bitrot. I'm fixing the merge conflict, but if another merge conflict happens before next review, I'll just wait for you to review the broken state as it's time consuming to keep up.
imperio force-pushed attr-dedup from a9a4bb0893
All checks were successful
/ format-checks (pull_request) Successful in 1m29s
to 05f10d80fd
Some checks failed
/ format-checks (pull_request) Failing after 1m31s
2026-09-01 20:15:03 +00:00
Compare
Author
Member

Fixed merge conflict. Ping @jsm28

For the review, I can only recommend to check that the function in attr-handlers.cc has the same code as the one removed from c-attribs.cc. Not too sure how to make the review easier for you, though. Sorry. :-/

Fixed merge conflict. Ping @jsm28 For the review, I can only recommend to check that the function in `attr-handlers.cc` has the same code as the one removed from `c-attribs.cc`. Not too sure how to make the review easier for you, though. Sorry. :-/
imperio force-pushed attr-dedup from 05f10d80fd
Some checks failed
/ format-checks (pull_request) Failing after 1m31s
to ccf771b4db
All checks were successful
/ format-checks (pull_request) Successful in 1m33s
2026-09-01 20:20:42 +00:00
Compare
cohenarthur left a comment

The code changes look good to me. Some of these functions will also be useful to the Rust frontend, so I'm in favor of the move and would like to see it merged.

The code changes look good to me. Some of these functions will also be useful to the Rust frontend, so I'm in favor of the move and would like to see it merged.
Member

Version 2 of this pull request has been stored. It includes the following commits:

  • Merge common attribute handling code between libgccjit and c-family. - ccf771b4db
<!-- pr-new-version --> Version 2 of this pull request has been stored. It includes the following commits: - Merge common attribute handling code between libgccjit and c-family. - ccf771b4db43886a4cfc63c4a5ef32ba41e21a6f
Author
Member

Ping @jsm28

Ping @jsm28
Owner

Breaking a line after DECL_P ( in the relocated validate_attr_args is not the normal style used. Other than that reformatting, the move of C front-end code is OK. Note that I have not reviewed functions relocated from the JIT front end such as handle_transaction_pure_attribute.

Breaking a line after `DECL_P (` in the relocated `validate_attr_args` is not the normal style used. Other than that reformatting, the move of C front-end code is OK. Note that I have not reviewed functions relocated from the JIT front end such as `handle_transaction_pure_attribute`.
Author
Member

Thanks! Then ping @dmalcolm :)

Thanks! Then ping @dmalcolm :)
dmalcolm approved these changes 2026-09-30 17:18:03 +00:00
dmalcolm left a comment

Thanks for the patch.

Note that handle_transaction_pure_attribute is only used by libgccjit (c-attribs.cc uses handle_tm_attribute) so this probably shouldn't be in the shared file.

The patch introduces some minor behavior changes to libgccjit for the following, but I believe only "pure", "const" and "returns_twice" are currently reachable (based on fn_attribute_to_string in jit-playback.cc)

  • "pure" in libgccjit with a non-FUNCTION_DECL used to ICE with gcc_unreachable but now emits a warning. Would be an improvement.
  • "pure" in libgccjit with a void-returning function (e.g. via GCC_JIT_FN_ATTRIBUTE_PURE) now warns when it didn't before. This could lead to previously-compiling gcc_jit_contexts failing after the patch. A behavior change, but I don't think it's a problem.
  • "const" in libgccjit on a void-returning function (e.g. via GCC_JIT_FN_ATTRIBUTE_CONST): gains a warning, so a similar behavior change. I think it's OK, for the same reasons.
  • "returns_twice" in libgccjit on a non-FUNCTION-DECL used to ICE with gcc_unreachable but now emits a warning (an improvement); not reachable from public jit API
  • "nothrow" same as "returns_twice", but reachable from API for builtins

dummy-frontend.cc can lose its definition of ATTR_EXCL after this patch (but we can defer this to a followup).

So I think this is OK from my POV, but @jsm28 might want you to drop the move of handle_transaction_pure_attribute. Patch is probably good enough as-is if this has already been tested thoroughly (bootstrap + make check-jit; check-gcc/check-c++), given how much of a pain this is causing you. Hence marking as "approved" but note the above.

Thanks for the patch. Note that `handle_transaction_pure_attribute` is only used by libgccjit (c-attribs.cc uses `handle_tm_attribute`) so this probably shouldn't be in the shared file. The patch introduces some minor behavior changes to libgccjit for the following, but I believe only `"pure"`, `"const"` and `"returns_twice"` are currently reachable (based on `fn_attribute_to_string` in jit-playback.cc) * "pure" in libgccjit with a non-FUNCTION_DECL used to ICE with gcc_unreachable but now emits a warning. Would be an improvement. * "pure" in libgccjit with a void-returning function (e.g. via GCC_JIT_FN_ATTRIBUTE_PURE) now warns when it didn't before. This could lead to previously-compiling gcc_jit_contexts failing after the patch. A behavior change, but I don't think it's a problem. * "const" in libgccjit on a void-returning function (e.g. via GCC_JIT_FN_ATTRIBUTE_CONST): gains a warning, so a similar behavior change. I think it's OK, for the same reasons. * "returns_twice" in libgccjit on a non-FUNCTION-DECL used to ICE with gcc_unreachable but now emits a warning (an improvement); not reachable from public jit API * "nothrow" same as "returns_twice", but reachable from API for builtins dummy-frontend.cc can lose its definition of ATTR_EXCL after this patch (but we can defer this to a followup). So I think this is OK from my POV, but @jsm28 might want you to drop the move of `handle_transaction_pure_attribute`. Patch is probably good enough as-is if this has already been tested thoroughly (bootstrap + make check-jit; check-gcc/check-c++), given how much of a pain this is causing you. Hence marking as "approved" but note the above.
imperio force-pushed attr-dedup from ccf771b4db
All checks were successful
/ format-checks (pull_request) Successful in 1m33s
to b12c2494c6
All checks were successful
/ format-checks (pull_request) Successful in 1m40s
2026-09-30 18:29:46 +00:00
Compare
Author
Member

Moved handle_transaction_pure_attribute back to dummy-frontend.cc.

Moved `handle_transaction_pure_attribute` back to `dummy-frontend.cc`.
Author
Member

Thanks for the review @dmalcolm ! I re-ran the testsuites (jit, C++ and C front-ends) and no new issue.

Thanks for the review @dmalcolm ! I re-ran the testsuites (jit, C++ and C front-ends) and no new issue.
@ -494,3 +279,3 @@
/* Handle a "transaction_pure" attribute. */
static tree
tree
Member

Please add back the static here.

Please add back the `static` here.
Author
Member

Done!

Done!
Member

Version 3 of this pull request has been stored. It includes the following commits:

  • Merge common attribute handling code between libgccjit and c-family. - b12c2494c6
<!-- pr-new-version --> Version 3 of this pull request has been stored. It includes the following commits: - Merge common attribute handling code between libgccjit and c-family. - b12c2494c6affd8ad4b232571ac43262cf946c57
imperio force-pushed attr-dedup from b12c2494c6
All checks were successful
/ format-checks (pull_request) Successful in 1m40s
to 6f44db8c8d
All checks were successful
/ format-checks (pull_request) Successful in 1m29s
2026-09-30 21:04:08 +00:00
Compare
@ -0,0 +204,4 @@
the previous one. */
const location_t curloc = input_location;
const location_t prevloc = DECL_P (
node[1]) ? DECL_SOURCE_LOCATION (node[1]) : curloc;
Member

The format checker doesn't error on this, but the original formatting was:

const location_t prevloc = 		
	    DECL_P (node[1]) ? DECL_SOURCE_LOCATION (node[1]) : curloc;
The format checker doesn't error on this, but the original formatting was: ```c const location_t prevloc = DECL_P (node[1]) ? DECL_SOURCE_LOCATION (node[1]) : curloc; ```
Author
Member

Done!

Done!
Member

Version 4 of this pull request has been stored. It includes the following commits:

  • Merge common attribute handling code between libgccjit and c-family. - 6f44db8c8d
<!-- pr-new-version --> Version 4 of this pull request has been stored. It includes the following commits: - Merge common attribute handling code between libgccjit and c-family. - 6f44db8c8d6c1c8186d215325d24e97c895f5630
imperio force-pushed attr-dedup from 6f44db8c8d
All checks were successful
/ format-checks (pull_request) Successful in 1m29s
to 341cc1d0cc
Some checks failed
/ format-checks (pull_request) Failing after 1m32s
2026-10-01 17:39:19 +00:00
Compare
antoyo approved these changes 2026-10-01 17:49:26 +00:00
Member

Version 5 of this pull request has been stored. It includes the following commits:

  • Merge common attribute handling code between libgccjit and c-family. - 341cc1d0cc
<!-- pr-new-version --> Version 5 of this pull request has been stored. It includes the following commits: - Merge common attribute handling code between libgccjit and c-family. - 341cc1d0ccdecdd12a0a137c283776a564c26983
imperio force-pushed attr-dedup from 341cc1d0cc
Some checks failed
/ format-checks (pull_request) Failing after 1m32s
to 8a16cf3552
All checks were successful
/ format-checks (pull_request) Successful in 1m35s
2026-10-01 17:52:25 +00:00
Compare
Author
Member

It was merged by @antoyo as commit 54df3a3d98. Closing then. Thanks everyone! I'll send follow-ups.

It was merged by @antoyo as commit 54df3a3d98b521ad0652b2fe23d9132bcf77d0fa. Closing then. Thanks everyone! I'll send follow-ups.
imperio closed this pull request 2026-10-02 09:49:19 +00:00
Member

Version 6 of this pull request has been stored. It includes the following commits:

  • Merge common attribute handling code between libgccjit and c-family. - 8a16cf3552
<!-- pr-new-version --> Version 6 of this pull request has been stored. It includes the following commits: - Merge common attribute handling code between libgccjit and c-family. - 8a16cf35521de45e2c0ffb804b2d828f31f3478f
Member

Pull Request versions:

# Base Head
1 ece564fdaa a9a4bb0893 (diff)
2 fc54ab94ad ccf771b4db (diff)
3 fc54ab94ad b12c2494c6 (diff)
4 fc54ab94ad 6f44db8c8d (diff)
5 fc54ab94ad 341cc1d0cc (diff)
6 fc54ab94ad 8a16cf3552 (diff)

In order to compare , clone this repository and run

PR=207
git fetch origin "refs/versioned_pull/${PR}/*:refs/versioned_pull/${PR}/*"
PRV1=1
PRV2=2
git range-diff "refs/versioned_pull/${PR}/${PRV1}/base..refs/versioned_pull/${PR}/${PRV1}/head"  "refs/versioned_pull/${PR}/${PRV2}/base..refs/versioned_pull/${PR}/${PRV2}/head"
<!-- pr-versions --> Pull Request versions: | # | Base | Head | | | - | ---- | ---- | - | | 1 | ece564fdaa15a0da008cedd881afcd3f0f4dbd5a | a9a4bb08931f95489f64af2a505a8dda432a8b71 | [(diff)](https://forge.sourceware.org/gcc/gcc.git/compare/ece564fdaa15a0da008cedd881afcd3f0f4dbd5a...a9a4bb08931f95489f64af2a505a8dda432a8b71) | | 2 | fc54ab94ad257f9ef43a7287a60c21734a7a288f | ccf771b4db43886a4cfc63c4a5ef32ba41e21a6f | [(diff)](https://forge.sourceware.org/gcc/gcc.git/compare/fc54ab94ad257f9ef43a7287a60c21734a7a288f...ccf771b4db43886a4cfc63c4a5ef32ba41e21a6f) | | 3 | fc54ab94ad257f9ef43a7287a60c21734a7a288f | b12c2494c6affd8ad4b232571ac43262cf946c57 | [(diff)](https://forge.sourceware.org/gcc/gcc.git/compare/fc54ab94ad257f9ef43a7287a60c21734a7a288f...b12c2494c6affd8ad4b232571ac43262cf946c57) | | 4 | fc54ab94ad257f9ef43a7287a60c21734a7a288f | 6f44db8c8d6c1c8186d215325d24e97c895f5630 | [(diff)](https://forge.sourceware.org/gcc/gcc.git/compare/fc54ab94ad257f9ef43a7287a60c21734a7a288f...6f44db8c8d6c1c8186d215325d24e97c895f5630) | | 5 | fc54ab94ad257f9ef43a7287a60c21734a7a288f | 341cc1d0ccdecdd12a0a137c283776a564c26983 | [(diff)](https://forge.sourceware.org/gcc/gcc.git/compare/fc54ab94ad257f9ef43a7287a60c21734a7a288f...341cc1d0ccdecdd12a0a137c283776a564c26983) | | 6 | fc54ab94ad257f9ef43a7287a60c21734a7a288f | 8a16cf35521de45e2c0ffb804b2d828f31f3478f | [(diff)](https://forge.sourceware.org/gcc/gcc.git/compare/fc54ab94ad257f9ef43a7287a60c21734a7a288f...8a16cf35521de45e2c0ffb804b2d828f31f3478f) | In order to compare , clone this repository and run ``` PR=207 git fetch origin "refs/versioned_pull/${PR}/*:refs/versioned_pull/${PR}/*" PRV1=1 PRV2=2 git range-diff "refs/versioned_pull/${PR}/${PRV1}/base..refs/versioned_pull/${PR}/${PRV1}/head" "refs/versioned_pull/${PR}/${PRV2}/base..refs/versioned_pull/${PR}/${PRV2}/head" ```
Member

Sent patch version 6 as a single email to gcc-patches mailing list gcc-patches@gcc.gnu.org and cc'd David Malcolm dmalcolm@redhat.com, josmyers@redhat.com, jit@gcc.gnu.org.
Cover letter

Sent patch version 6 as a single email to gcc-patches mailing list <gcc-patches@gcc.gnu.org> and cc'd David Malcolm <dmalcolm@redhat.com>, <josmyers@redhat.com>, <jit@gcc.gnu.org>. [Cover letter](https://inbox.sourceware.org/gcc-patches/bmm.hmtzzcx8f0.gcc.gcc.imperio.207.6.0@forge-stage.sourceware.org)
imperio deleted branch attr-dedup 2026-10-07 12:03:17 +00:00
All checks were successful
/ format-checks (pull_request) Successful in 1m35s

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No assignees
6 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!207
No description provided.