C/C++ support for OpenACC init,set,shutdown directives. #225

Closed
galindos wants to merge 1 commit from galindos/gcc-fork-galindos:talkysafe/wip/init_set_shutdown/c_cpp into trunk
Member

This patch add OpenACC init,set,shutdown directives support for the C
and C++ front-ends.

An unexpected runtime error was fixed: When the device_type clause had
the argument as *, the set directive was passing an invalid argument to
the runtime library.

The bug 126507 was resolved (dtype alias for device_type).

gcc/c-family/ChangeLog:

* c-common.h (c_finish_oacc_executable_directive): Declare.
* c-omp.cc (oacc_eval_device_type): New.
(c_finish_oacc_executable_directive): New.  Lower init, set and
shutdown to GOACC builtins; map set's device_type(*) to
GOMP_DEVICE_DEFAULT.
* c-pragma.cc (oacc_pragmas): Register init, set and shutdown.
* c-pragma.h (enum pragma_kind): Add PRAGMA_OACC_INIT,
PRAGMA_OACC_SET and PRAGMA_OACC_SHUTDOWN.
(enum pragma_omp_clause): Add PRAGMA_OACC_CLAUSE_DEVICE_NUM and
PRAGMA_OACC_CLAUSE_DEVICE_TYPE alias.

gcc/c/ChangeLog:

* c-parser.cc (c_parser_omp_clause_name): Recognize device_num and
dtype as an alias of device_type.
(c_parser_oacc_single_int_clause): Allow device_num 0; clamp
non-positive device_num to 0.
(c_parser_oacc_clause_device_type): New.  Parse OpenACC
device_type/dtype arguments.
(c_parser_oacc_all_clauses): Handle DEVICE_NUM and OpenACC
DEVICE_TYPE.
(OACC_INIT_CLAUSE_MASK, OACC_SHUTDOWN_CLAUSE_MASK,
OACC_SET_CLAUSE_MASK): New.
(c_parser_oacc_executable_directive): New.
(c_parser_omp_construct): Handle init, set and shutdown.
* c-typeck.cc (c_finish_omp_clauses): Accept OMP_CLAUSE_DEVICE_NUM.

gcc/cp/ChangeLog:

* parser.cc (cp_parser_omp_clause_name): Recognize device_num and
dtype as an alias of device_type.
(cp_parser_oacc_single_int_clause): Allow device_num 0; clamp
non-positive device_num to 0.
(cp_parser_oacc_clause_device_type): New.  Parse OpenACC
device_type/dtype arguments.
(cp_parser_oacc_all_clauses): Handle DEVICE_NUM and OpenACC
DEVICE_TYPE.
(OACC_INIT_CLAUSE_MASK, OACC_SHUTDOWN_CLAUSE_MASK,
OACC_SET_CLAUSE_MASK): New.
(cp_parser_oacc_executable_directive): New.
(cp_parser_omp_construct): Handle init, set and shutdown.
(cp_parser_pragma): Allow init, set and shutdown in statement
context.
* semantics.cc (finish_omp_clauses): Handle OMP_CLAUSE_DEVICE_NUM
like other integral OpenACC clauses, including template
instantiation; require a non-negative value.

gcc/fortran/ChangeLog:

* openmp.cc (gfc_match_omp_clauses): Accept dtype as an alias of
OpenACC device_type.
* trans-openmp.cc (gfc_trans_oacc_executable_directive): For set,
map device_type(*) to GOMP_DEVICE_DEFAULT.

gcc/ChangeLog:

* tree-core.h (enum omp_clause_code): Add OMP_CLAUSE_DEVICE_NUM.
(enum oacc_clause_device_type_kind): New.
(struct tree_omp_clause): Add oacc_device_type_kind.
* tree-pretty-print.cc (dump_omp_clause): Dump DEVICE_NUM and
OpenACC DEVICE_TYPE kinds.
* tree.cc (omp_clause_num_ops, omp_clause_code_name): Handle
DEVICE_NUM.
* tree.h (OMP_CLAUSE_OACC_DEVICE_TYPE_KIND): Define.

gcc/testsuite/ChangeLog:

* c-c++-common/goacc/uninit-if-clause.c: Test uninitialized if on
init.
* c-c++-common/goacc/update-if_present-2.c: Expect errors for
if_present on init and shutdown.
* gfortran.dg/goacc/acc-set-1.f90: Test set with device_type(*).
* c-c++-common/goacc/acc-dtype-1.c: New test.
* c-c++-common/goacc/acc-init-1.c: New test.
* c-c++-common/goacc/acc-init-clauses-1.c: New test.
* c-c++-common/goacc/acc-set-1.c: New test.
* c-c++-common/goacc/acc-set-clauses-1.c: New test.
* c-c++-common/goacc/acc-shutdown-1.c: New test.
* c-c++-common/goacc/acc-shutdown-clauses-1.c: New test.
* gfortran.dg/goacc/acc-dtype-1.f90: New test.

Signed-off-by: Sebastian Galindo sebastian.galindo143@gmail.com
CC: tburnus@baylibre.com, tschwinge@baylibre.com

This patch add OpenACC init,set,shutdown directives support for the C and C++ front-ends. An unexpected runtime error was fixed: When the device_type clause had the argument as *, the set directive was passing an invalid argument to the runtime library. The bug 126507 was resolved (dtype alias for device_type). gcc/c-family/ChangeLog: * c-common.h (c_finish_oacc_executable_directive): Declare. * c-omp.cc (oacc_eval_device_type): New. (c_finish_oacc_executable_directive): New. Lower init, set and shutdown to GOACC builtins; map set's device_type(*) to GOMP_DEVICE_DEFAULT. * c-pragma.cc (oacc_pragmas): Register init, set and shutdown. * c-pragma.h (enum pragma_kind): Add PRAGMA_OACC_INIT, PRAGMA_OACC_SET and PRAGMA_OACC_SHUTDOWN. (enum pragma_omp_clause): Add PRAGMA_OACC_CLAUSE_DEVICE_NUM and PRAGMA_OACC_CLAUSE_DEVICE_TYPE alias. gcc/c/ChangeLog: * c-parser.cc (c_parser_omp_clause_name): Recognize device_num and dtype as an alias of device_type. (c_parser_oacc_single_int_clause): Allow device_num 0; clamp non-positive device_num to 0. (c_parser_oacc_clause_device_type): New. Parse OpenACC device_type/dtype arguments. (c_parser_oacc_all_clauses): Handle DEVICE_NUM and OpenACC DEVICE_TYPE. (OACC_INIT_CLAUSE_MASK, OACC_SHUTDOWN_CLAUSE_MASK, OACC_SET_CLAUSE_MASK): New. (c_parser_oacc_executable_directive): New. (c_parser_omp_construct): Handle init, set and shutdown. * c-typeck.cc (c_finish_omp_clauses): Accept OMP_CLAUSE_DEVICE_NUM. gcc/cp/ChangeLog: * parser.cc (cp_parser_omp_clause_name): Recognize device_num and dtype as an alias of device_type. (cp_parser_oacc_single_int_clause): Allow device_num 0; clamp non-positive device_num to 0. (cp_parser_oacc_clause_device_type): New. Parse OpenACC device_type/dtype arguments. (cp_parser_oacc_all_clauses): Handle DEVICE_NUM and OpenACC DEVICE_TYPE. (OACC_INIT_CLAUSE_MASK, OACC_SHUTDOWN_CLAUSE_MASK, OACC_SET_CLAUSE_MASK): New. (cp_parser_oacc_executable_directive): New. (cp_parser_omp_construct): Handle init, set and shutdown. (cp_parser_pragma): Allow init, set and shutdown in statement context. * semantics.cc (finish_omp_clauses): Handle OMP_CLAUSE_DEVICE_NUM like other integral OpenACC clauses, including template instantiation; require a non-negative value. gcc/fortran/ChangeLog: * openmp.cc (gfc_match_omp_clauses): Accept dtype as an alias of OpenACC device_type. * trans-openmp.cc (gfc_trans_oacc_executable_directive): For set, map device_type(*) to GOMP_DEVICE_DEFAULT. gcc/ChangeLog: * tree-core.h (enum omp_clause_code): Add OMP_CLAUSE_DEVICE_NUM. (enum oacc_clause_device_type_kind): New. (struct tree_omp_clause): Add oacc_device_type_kind. * tree-pretty-print.cc (dump_omp_clause): Dump DEVICE_NUM and OpenACC DEVICE_TYPE kinds. * tree.cc (omp_clause_num_ops, omp_clause_code_name): Handle DEVICE_NUM. * tree.h (OMP_CLAUSE_OACC_DEVICE_TYPE_KIND): Define. gcc/testsuite/ChangeLog: * c-c++-common/goacc/uninit-if-clause.c: Test uninitialized if on init. * c-c++-common/goacc/update-if_present-2.c: Expect errors for if_present on init and shutdown. * gfortran.dg/goacc/acc-set-1.f90: Test set with device_type(*). * c-c++-common/goacc/acc-dtype-1.c: New test. * c-c++-common/goacc/acc-init-1.c: New test. * c-c++-common/goacc/acc-init-clauses-1.c: New test. * c-c++-common/goacc/acc-set-1.c: New test. * c-c++-common/goacc/acc-set-clauses-1.c: New test. * c-c++-common/goacc/acc-shutdown-1.c: New test. * c-c++-common/goacc/acc-shutdown-clauses-1.c: New test. * gfortran.dg/goacc/acc-dtype-1.f90: New test. Signed-off-by: Sebastian Galindo <sebastian.galindo143@gmail.com> CC: tburnus@baylibre.com, tschwinge@baylibre.com
Member

Hi @galindos. 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 @galindos. 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).
Author
Member

/preview

/preview
Member

Sent patch version 1 as a single email to @galindos's email address.
Message ID is <bmm.hloc7kwmka.gcc.gcc.galindos.225.1.0@forge-stage.sourceware.org>.

Sent patch version 1 as a single email to @galindos's email address. Message ID is `<bmm.hloc7kwmka.gcc.gcc.galindos.225.1.0@forge-stage.sourceware.org>`.
galindos force-pushed talkysafe/wip/init_set_shutdown/c_cpp from d5b0ae1ee1
Some checks failed
/ format-checks (pull_request) Failing after 3m15s
to 3128ae9fbb
Some checks failed
/ format-checks (pull_request) Failing after 1m36s
2026-08-27 03:04:45 +00:00
Compare
galindos force-pushed talkysafe/wip/init_set_shutdown/c_cpp from 3128ae9fbb
Some checks failed
/ format-checks (pull_request) Failing after 1m36s
to 4d1ae1abe7
All checks were successful
/ format-checks (pull_request) Successful in 1m28s
2026-08-27 03:07:56 +00:00
Compare
Author
Member

/preview

/preview
Member

Sent patch version 1 as a single email to @galindos's email address.
Message ID is <bmm.hlq02zt3o8.gcc.gcc.galindos.225.1.0@forge-stage.sourceware.org>.

Sent patch version 1 as a single email to @galindos's email address. Message ID is `<bmm.hlq02zt3o8.gcc.gcc.galindos.225.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:

  • C/C++ support for OpenACC init,set,shutdown directives. - 4d1ae1abe7
<!-- pr-new-version --> Version 1 of this pull request has been stored. It includes the following commits: - C/C++ support for OpenACC init,set,shutdown directives. - 4d1ae1abe734ff7cd607af9a1d5b4141b7b906f4
Member

Pull Request versions:

# Base Head
1 b085ae4b49 4d1ae1abe7 (diff)

In order to compare , clone this repository and run

PR=225
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 | b085ae4b49b41e146c0a6a6c16c8c588438b9528 | 4d1ae1abe734ff7cd607af9a1d5b4141b7b906f4 | [(diff)](https://forge.sourceware.org/gcc/gcc.git/compare/b085ae4b49b41e146c0a6a6c16c8c588438b9528...4d1ae1abe734ff7cd607af9a1d5b4141b7b906f4) | In order to compare , clone this repository and run ``` PR=225 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 1 as a single email to gcc-patches mailing list gcc-patches@gcc.gnu.org and cc'd tburnus@baylibre.com, tschwinge@baylibre.com.
Cover letter

Sent patch version 1 as a single email to gcc-patches mailing list <gcc-patches@gcc.gnu.org> and cc'd tburnus@baylibre.com, tschwinge@baylibre.com. [Cover letter](https://inbox.sourceware.org/gcc-patches/bmm.hlq046v70c.gcc.gcc.galindos.225.1.0@forge-stage.sourceware.org)
Owner

An unexpected runtime error was fixed: When the device_type clause had the argument as *, the set directive was passing an invalid argument to the runtime library.

Please make that a separate patch submission (including the corresponding test case updates).

The bug 126507 was resolved (dtype alias for device_type).

..., and that one as well, separately. Put [PR126507] at the end of the Git commit summary line, and PR fortran/126507 in the ChangeLog updates as part of the Git commit log.

(I'm now reviewing the C, C++ changes here.)

> An unexpected runtime error was fixed: When the device_type clause had the argument as *, the set directive was passing an invalid argument to the runtime library. Please make that a separate patch submission (including the corresponding test case updates). > The bug 126507 was resolved (dtype alias for device_type). ..., and that one as well, separately. Put `[PR126507]` at the end of the Git commit summary line, and `PR fortran/126507` in the ChangeLog updates as part of the Git commit log. (I'm now reviewing the C, C++ changes here.)
galindos closed this pull request 2026-10-05 03:03:57 +00:00
All checks were successful
/ format-checks (pull_request) Successful in 1m28s

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!225
No description provided.