Elsewhere in the Fortran front-end, the class_pointer attribute is
used for BT_CLASS entities instead of the pointer attribute. This patch
follows suit for OpenACC. I couldn't actually come up with a test case
where this makes a difference (i.e., where "class_pointer" and "pointer"
have different values at this point in the code), but this may nonetheless
fix a latent bug.

gcc/fortran/
        * trans-openmp.c (gfc_trans_omp_clauses): Use class_pointer attribute
        for BT_CLASS.

(cherry picked from commit f743fe231663e32d52db987650d0ec3381a777af)
---
 gcc/fortran/ChangeLog.omp  | 7 +++++++
 gcc/fortran/trans-openmp.c | 5 ++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/ChangeLog.omp b/gcc/fortran/ChangeLog.omp
index 9e0cf7198acf..2dd82a70cb71 100644
--- a/gcc/fortran/ChangeLog.omp
+++ b/gcc/fortran/ChangeLog.omp
@@ -1,3 +1,10 @@
+2021-02-24  Julian Brown  <jul...@codesourcery.com>
+
+       Backport from mainline
+
+       * trans-openmp.c (gfc_trans_omp_clauses): Use class_pointer attribute
+       for BT_CLASS.
+
 2021-02-24  Julian Brown  <jul...@codesourcery.com>
 
        Backport from mainline
diff --git a/gcc/fortran/trans-openmp.c b/gcc/fortran/trans-openmp.c
index e53f7ebb7d7f..d0e299b02142 100644
--- a/gcc/fortran/trans-openmp.c
+++ b/gcc/fortran/trans-openmp.c
@@ -2973,7 +2973,10 @@ gfc_trans_omp_clauses (stmtblock_t *block, 
gfc_omp_clauses *clauses,
                  if (lastcomp->u.c.component->ts.type == BT_DERIVED
                      || lastcomp->u.c.component->ts.type == BT_CLASS)
                    {
-                     if (sym_attr.pointer || (openacc && sym_attr.allocatable))
+                     bool pointer
+                       = (lastcomp->u.c.component->ts.type == BT_CLASS
+                          ? sym_attr.class_pointer : sym_attr.pointer);
+                     if (pointer || (openacc && sym_attr.allocatable))
                        {
                          tree data, size;
 
-- 
2.29.2

Reply via email to