This patch (by Cesar) changes the way C++ references are mapped in
OpenACC regions, fixing an ICE in the non-scalar-data.C testcase.

Post-patch, references are mapped like this (from the omplower dump):

map(force_present:*x [len: 4]) map(firstprivate ref:x [pointer assign, bias: 0])

Tested with offloading to NVPTX and bootstrapped. OK for trunk?

Thanks,

Julian

ChangeLog

2018-09-09  Cesar Philippidis  <ce...@codesourcery.com>
            Julian Brown  <jul...@codesourcery.com>

        PR middle-end/86336

        gcc/cp/
        * semantics.c (finish_omp_clauses): Map C++ references by value and
        FIRSTPRIVATE_REFERENCE.

        * gimplify.c (gimplify_scan_omp_clauses): Remove FIRSTPRIVATE_REFERENCE
        mappings in OpenACC data regions.
        (gimplify_adjust_omp_clauses_1): Update handling of mapping of C++
        references.

        libgomp/
        * testsuite/libgomp.oacc-c++/non-scalar-data.C: Remove XFAIL.
commit fed5f1044b3d7add83065b3bbe2ba2a95a1e95ce
Author: Julian Brown <jul...@codesourcery.com>
Date:   Thu Sep 6 15:32:50 2018 -0700

    [OpenACC] C++ reference mapping
    
    2018-09-09  Cesar Philippidis  <ce...@codesourcery.com>
    	    Julian Brown  <jul...@codesourcery.com>
    
    	gcc/cp/
    	* semantics.c (finish_omp_clauses): Map C++ references by value and
    	FIRSTPRIVATE_REFERENCE.
    
    	* gimplify.c (gimplify_scan_omp_clauses): Remove FIRSTPRIVATE_REFERENCE
    	mappings in OpenACC data regions.
    	(gimplify_adjust_omp_clauses_1): Update handling of mapping of C++
    	references.
    
    	libgomp/
    	* testsuite/libgomp.oacc-c++/non-scalar-data.C: Remove XFAIL.

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 676de01..707f054 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -6877,7 +6877,8 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
 	handle_map_references:
 	  if (!remove
 	      && !processing_template_decl
-	      && (ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP
+	      && ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP
+		  || ort == C_ORT_ACC)
 	      && TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c))))
 	    {
 	      t = OMP_CLAUSE_DECL (c);
diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index dbd0f0e..4011cb2 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -8556,7 +8556,8 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p,
 
       if (code == OACC_DATA
 	  && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
-	  && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FIRSTPRIVATE_POINTER)
+	  && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FIRSTPRIVATE_POINTER
+	      || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FIRSTPRIVATE_REFERENCE))
 	remove = true;
       if (remove)
 	*list_p = OMP_CLAUSE_CHAIN (c);
@@ -8872,7 +8873,9 @@ gimplify_adjust_omp_clauses_1 (splay_tree_node n, void *data)
 	  OMP_CLAUSE_CHAIN (nc) = OMP_CLAUSE_CHAIN (clause);
 	  OMP_CLAUSE_CHAIN (clause) = nc;
 	}
-      else if (gimplify_omp_ctxp->target_firstprivatize_array_bases
+      else if ((((gimplify_omp_ctxp->region_type & ORT_ACC)
+		 && lang_GNU_CXX ())
+		|| gimplify_omp_ctxp->target_firstprivatize_array_bases)
 	       && lang_hooks.decls.omp_privatize_by_reference (decl))
 	{
 	  OMP_CLAUSE_DECL (clause) = build_simple_mem_ref (decl);
diff --git a/libgomp/testsuite/libgomp.oacc-c++/non-scalar-data.C b/libgomp/testsuite/libgomp.oacc-c++/non-scalar-data.C
index 8e4b296..e5f8707 100644
--- a/libgomp/testsuite/libgomp.oacc-c++/non-scalar-data.C
+++ b/libgomp/testsuite/libgomp.oacc-c++/non-scalar-data.C
@@ -1,8 +1,7 @@
 // Ensure that a non-scalar dummy arguments which are implicitly used inside
 // offloaded regions are properly mapped using present_or_copy semantics.
 
-// { dg-xfail-if "TODO" { *-*-* } }
-// { dg-excess-errors "ICE" }
+// { dg-do run }
 
 #include <cassert>
 

Reply via email to