PR fortran/126507

gcc/c/ChangeLog:

        * c-parser.cc (c_parser_omp_clause_name): Add the dtype alias to
        device_type parsing.

gcc/cp/ChangeLog:

        * parser.cc (cp_parser_omp_clause_name): Add the dtype alias to
        device_type parsing.

gcc/fortran/ChangeLog:

        * openmp.cc (gfc_match_omp_clauses): Add the dtype alias to the
        device_type parsing.

gcc/testsuite/ChangeLog:

        * c-c++-common/goacc/acc-dtype-1.c: New test.
        * gfortran.dg/goacc/acc-dtype-1.f90: New test.

Signed-off-by: Sebastian Galindo <[email protected]>
---
 gcc/c/c-parser.cc                             |  2 +-
 gcc/cp/parser.cc                              |  2 +-
 gcc/fortran/openmp.cc                         |  8 +++-
 .../c-c++-common/goacc/acc-dtype-1.c          | 40 +++++++++++++++++++
 .../gfortran.dg/goacc/acc-dtype-1.f90         | 36 +++++++++++++++++
 5 files changed, 84 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/c-c++-common/goacc/acc-dtype-1.c
 create mode 100644 gcc/testsuite/gfortran.dg/goacc/acc-dtype-1.f90

diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index b089e75e858..671f79cf661 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -16531,7 +16531,7 @@ c_parser_omp_clause_name (c_parser *parser)
            result = PRAGMA_OACC_CLAUSE_DEVICE_NUM;
          else if (!strcmp ("device_resident", p))
            result = PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT;
-         else if (!strcmp ("device_type", p))
+         else if (!strcmp ("device_type", p) || !strcmp ("dtype", p))
            result = PRAGMA_OMP_CLAUSE_DEVICE_TYPE;
          else if (!strcmp ("dist_schedule", p))
            result = PRAGMA_OMP_CLAUSE_DIST_SCHEDULE;
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 96232ece981..5f83a8e0fd6 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -41518,7 +41518,7 @@ cp_parser_omp_clause_name (cp_parser *parser)
            result = PRAGMA_OACC_CLAUSE_DEVICE_NUM;
          else if (!strcmp ("device_resident", p))
            result = PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT;
-         else if (!strcmp ("device_type", p))
+         else if (!strcmp ("device_type", p) || !strcmp ("dtype", p))
            result = PRAGMA_OMP_CLAUSE_DEVICE_TYPE;
          else if (!strcmp ("dist_schedule", p))
            result = PRAGMA_OMP_CLAUSE_DIST_SCHEDULE;
diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index a2c825401e3..95b0c4cf4e1 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -3321,8 +3321,12 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, const 
omp_mask mask,
                                           allow_derived))
            continue;
          if ((mask & OMP_CLAUSE_DEVICE_TYPE) && openacc
-             && gfc_match_dupl_check (!c->oacc_device_type_present,
-                                      "device_type", true) == MATCH_YES
+             && (gfc_match_dupl_check (!c->oacc_device_type_present,
+                                       "device_type", true)
+                   == MATCH_YES
+                 || gfc_match_dupl_check (!c->oacc_device_type_present,
+                                          "dtype", true)
+                      == MATCH_YES)
              && match_oacc_device_type (c) == MATCH_YES)
            continue;
          if ((mask & OMP_CLAUSE_DEVICE_TYPE) && !openacc
diff --git a/gcc/testsuite/c-c++-common/goacc/acc-dtype-1.c 
b/gcc/testsuite/c-c++-common/goacc/acc-dtype-1.c
new file mode 100644
index 00000000000..75b4229cbe1
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/goacc/acc-dtype-1.c
@@ -0,0 +1,40 @@
+/* Test OpenACC dtype abbreviation for device_type on init/set/shutdown.  */
+
+/* { dg-do compile } */
+/* { dg-additional-options "-fdump-tree-original" } */
+
+void
+dtype_init (void)
+{
+  #pragma acc init dtype(host)
+}
+/* { dg-final { scan-tree-dump-times "__builtin_GOACC_init \\(-1, 2\\)" 1 
"original" } } */
+
+void
+dtype_init_star (void)
+{
+  #pragma acc init dtype(*)
+}
+/* { dg-final { scan-tree-dump-times "__builtin_GOACC_init \\(-1, 0\\)" 1 
"original" } } */
+
+void
+dtype_set_host (void)
+{
+  #pragma acc set dtype(nvidia)
+}
+/* { dg-final { scan-tree-dump-times "__builtin_GOACC_set_device \\(-1, 5\\)" 
1 "original" } } */
+
+void
+dtype_set_star (void)
+{
+  /* dtype(*) on set maps to GOMP_DEVICE_DEFAULT.  */
+  #pragma acc set dtype(*)
+}
+/* { dg-final { scan-tree-dump-times "__builtin_GOACC_set_device \\(-1, 1\\)" 
1 "original" } } */
+
+void
+dtype_shutdown (void)
+{
+  #pragma acc shutdown dtype(radeon) device_num(1)
+}
+/* { dg-final { scan-tree-dump-times "__builtin_GOACC_shutdown \\(1, 8\\)" 1 
"original" } } */
diff --git a/gcc/testsuite/gfortran.dg/goacc/acc-dtype-1.f90 
b/gcc/testsuite/gfortran.dg/goacc/acc-dtype-1.f90
new file mode 100644
index 00000000000..7688155476f
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/goacc/acc-dtype-1.f90
@@ -0,0 +1,36 @@
+! Test OpenACC dtype abbreviation for device_type on init/set/shutdown.
+
+! { dg-do compile }
+! { dg-additional-options "-fdump-tree-original" }
+
+subroutine dtype_init
+  implicit none
+  !$acc init dtype(host)
+end subroutine dtype_init
+
+subroutine dtype_init_star
+  implicit none
+  !$acc init dtype(*)
+end subroutine dtype_init_star
+
+subroutine dtype_set_host
+  implicit none
+  !$acc set dtype(nvidia)
+end subroutine dtype_set_host
+
+subroutine dtype_set_star
+  implicit none
+  ! dtype(*) on set maps to GOMP_DEVICE_DEFAULT.
+  !$acc set dtype(*)
+end subroutine dtype_set_star
+
+subroutine dtype_shutdown
+  implicit none
+  !$acc shutdown dtype(radeon) device_num(1)
+end subroutine dtype_shutdown
+
+! { dg-final { scan-tree-dump-times "__builtin_GOACC_init \\(-1, 2\\)" 1 
"original" } }
+! { dg-final { scan-tree-dump-times "__builtin_GOACC_init \\(-1, 0\\)" 1 
"original" } }
+! { dg-final { scan-tree-dump-times "__builtin_GOACC_set_device \\(-1, 5\\)" 1 
"original" } }
+! { dg-final { scan-tree-dump-times "__builtin_GOACC_set_device \\(-1, 1\\)" 1 
"original" } }
+! { dg-final { scan-tree-dump-times "__builtin_GOACC_shutdown \\(1, 8\\)" 1 
"original" } }
-- 
2.55.0

Reply via email to