While for data sharing (e.g. "parallel") the
predetermined sharing (e.g.) for compiler-generated
variables did work, this did not happen for target
mapping – causing errors with "defaultmap(none)".

It is not completely clear to my how to best handle
this case. In most cases, the auxiliary variable is
scalar and never modified – currently, they become
"map(tofrom:)" which looks like a missed optimization.

I was thinking of simply marking them as
"nflags |= GOVD_FIRSTPRIVATE" but I am not sure whether
that would always make sense, either. In any case, a
simple usage would bypass the
"implicit mapping of assumed size array"
diagnostic in gfc_omp_finish_clause.

One could also use a value returned by the hook,
but currently it is tailored for shared memory
use only. A fix would be either a new argument
("bool for_mapping") plus special handling or
a new hook. In any case, the current hook has:

For C and most cases of C++:
  OMP_CLAUSE_DEFAULT_SHARED
except that C++ return for current_class_ptr:
  OMP_CLAUSE_DEFAULT_FIRSTPRIVATE

But Fortran is very complex. A simple handling
is also not possible as some things (like
a C++/Fortran class pointer or probably
Cray pointer) need pointer mapping.
[C++: RTTI/dynamic_cast permitted; Fortran:
RTTI + virtual calls permitted.]

Hence, I went for the simple solution.

OK for the trunk? If is, is it worthwhile to
backport to the GCC 10 branch?


Tobias

-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter
[OpenMP] Fix mapping of artificial variables (PR94874)

gcc/
2020-05-08  Tobias Burnus  <tob...@codesourcery.com>

	PR middle-end/94874
	* gimplify.c (omp_notice_variable): For mapping, also call
	lang_hooks.decls.omp_predetermined_sharing.

gcc/testsuite/
2020-05-08  Thomas Schwinge  <tho...@codesourcery.com>
	    Tobias Burnus  <tob...@codesourcery.com>

	PR middle-end/94874
	* c-c++-common/gomp/pr94874.c: New.

 gcc/gimplify.c                            |  5 ++++-
 gcc/testsuite/c-c++-common/gomp/pr94874.c | 27 +++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 1d532e6f373..4c5eb0b3d54 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -7441,7 +7441,10 @@ omp_notice_variable (struct gimplify_omp_ctx *ctx, tree decl, bool in_code)
 		    gdmk = GDMK_SCALAR;
 		  else
 		    gdmk = GDMK_AGGREGATE;
-		  if (ctx->defaultmap[gdmk] == 0)
+		  if (lang_hooks.decls.omp_predetermined_sharing (decl)
+		      != OMP_CLAUSE_DEFAULT_UNSPECIFIED)
+		    ;  /* Handled by lang_hooks.decls.omp_finish_clause.  */
+		  else if (ctx->defaultmap[gdmk] == 0)
 		    {
 		      tree d = lang_hooks.decls.omp_report_decl (decl);
 		      error ("%qE not specified in enclosing %<target%>",
diff --git a/gcc/testsuite/c-c++-common/gomp/pr94874.c b/gcc/testsuite/c-c++-common/gomp/pr94874.c
new file mode 100644
index 00000000000..36da2471a80
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/pr94874.c
@@ -0,0 +1,27 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fdump-tree-gimple" } */
+
+#include <stddef.h>
+
+size_t
+vla (int array_li)
+{
+  float array[array_li];
+  size_t size1, size2;
+
+#pragma omp parallel default(none) shared(size1, array)
+  size1 = sizeof array;
+
+#pragma omp target defaultmap(none) map(from:size2) map(alloc:array)
+  size2 = sizeof array;
+
+  return size1 + size2;
+}
+
+/* C */
+/* { dg-final { scan-tree-dump "omp parallel .*shared\\(array_li\.\[0-9\]\\)" "gimple" { target { ! c++ } } } } */
+/* { dg-final { scan-tree-dump "omp target .*map\\(tofrom:array_li\.\[0-9\] " "gimple" { target { ! c++ } } } } */
+
+/* C++ */
+/* { dg-final { scan-tree-dump "omp parallel .*shared\\(D\.\[0-9\]*\\)" "gimple" { target { c++ } } } } */
+/* { dg-final { scan-tree-dump "omp target .*map\\(tofrom:D\.\[0-9\]* " "gimple" { target { c++ } } } } */

Reply via email to