GCC currently raises a parse error for indirect accesses to struct
members, where the base of the access is a reference to a pointer.
This patch fixes that case.

OK for trunk?

Thanks,

Julian

2021-05-14  Julian Brown  <jul...@codesourcery.com>

gcc/cp/
        * semantics.c (finish_omp_clauses): Handle components of references to
        pointers to structs.

libgomp/
        * testsuite/libgomp.oacc-c++/deep-copy-17.C: Update test.
---
 gcc/cp/semantics.c                                | 7 ++++++-
 libgomp/testsuite/libgomp.oacc-c++/deep-copy-17.C | 2 +-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 0d590c318fb..b09023f741c 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -7670,7 +7670,12 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type 
ort)
          if ((ort == C_ORT_ACC || ort == C_ORT_OMP)
              && TREE_CODE (t) == COMPONENT_REF
              && TREE_CODE (TREE_OPERAND (t, 0)) == INDIRECT_REF)
-           t = TREE_OPERAND (TREE_OPERAND (t, 0), 0);
+           {
+             t = TREE_OPERAND (TREE_OPERAND (t, 0), 0);
+             /* References to pointers have a double indirection here.  */
+             if (TREE_CODE (t) == INDIRECT_REF)
+               t = TREE_OPERAND (t, 0);
+           }
          if (TREE_CODE (t) == COMPONENT_REF
              && ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP
                  || ort == C_ORT_ACC)
diff --git a/libgomp/testsuite/libgomp.oacc-c++/deep-copy-17.C 
b/libgomp/testsuite/libgomp.oacc-c++/deep-copy-17.C
index dacbb520f3d..e038e9e3802 100644
--- a/libgomp/testsuite/libgomp.oacc-c++/deep-copy-17.C
+++ b/libgomp/testsuite/libgomp.oacc-c++/deep-copy-17.C
@@ -83,7 +83,7 @@ void strrp (void)
   a[0] = 8;
   c[0] = 10;
   e[0] = 12;
-  #pragma acc parallel copy(n->a[0:10], n->c[0:10], n->e[0:10])
+  #pragma acc parallel copy(n->a[0:10], n->b, n->c[0:10], n->d, n->e[0:10])
   {
     n->a[0] = n->c[0] + n->e[0];
   }
-- 
2.29.2

Reply via email to