public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-10637] openmp: Fix up omp_check_private [PR101535]
@ 2022-05-10  8:20 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2022-05-10  8:20 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:69f1936c6700403fb94920f44346a5e2a66e2f86

commit r10-10637-g69f1936c6700403fb94920f44346a5e2a66e2f86
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed Jul 21 09:45:02 2021 +0200

    openmp: Fix up omp_check_private [PR101535]
    
    The target data construct shouldn't affect omp_check_private, unless
    the decl there is privatized (use_device_* clauses).  The routine
    had some code for that, but it just did continue; in a loop that looped
    only if the region type is one of selected 4 kinds, so effectively resulted
    in return false; instead of looping again.  And not diagnosing lastprivate
    (or reduction etc.) on a variable that is private to containing parallel
    results in ICEs later on, as there is no original list item to which store
    the last result.
    The target construct is unclear as it has an implicit parallel region
    and it is not obvious if the data privatization clauses on the construct
    shall be treated as data privatization on the implicit parallel or just
    on the target.  For now treat those as privatization on the implicit
    parallel, but treat map clauses as shared on the implicit parallel.
    
    2021-07-21  Jakub Jelinek  <jakub@redhat.com>
    
            PR middle-end/101535
            * gimplify.c (omp_check_private): Properly skip ORT_TARGET_DATA
            contexts in which decl isn't privatized and for ORT_TARGET return
            false if decl is mapped.
    
            * c-c++-common/gomp/pr101535-1.c: New test.
            * c-c++-common/gomp/pr101535-2.c: New test.
    
    (cherry picked from commit b136b7a78774107943fe94051c42b5a968a3ad3f)

Diff:
---
 gcc/gimplify.c                               | 21 ++++++++++++++-----
 gcc/testsuite/c-c++-common/gomp/pr101535-1.c | 31 ++++++++++++++++++++++++++++
 gcc/testsuite/c-c++-common/gomp/pr101535-2.c | 11 ++++++++++
 3 files changed, 58 insertions(+), 5 deletions(-)

diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 89a4ae087ce..ff81ede350d 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -7738,7 +7738,13 @@ omp_check_private (struct gimplify_omp_ctx *ctx, tree decl, bool copyprivate)
 
       if ((ctx->region_type & (ORT_TARGET | ORT_TARGET_DATA)) != 0
 	  && (n == NULL || (n->value & GOVD_DATA_SHARE_CLASS) == 0))
-	continue;
+	{
+	  if ((ctx->region_type & ORT_TARGET_DATA) != 0
+	      || n == NULL
+	      || (n->value & GOVD_MAP) == 0)
+	    continue;
+	  return false;
+	}
 
       if (n != NULL)
 	{
@@ -7747,11 +7753,16 @@ omp_check_private (struct gimplify_omp_ctx *ctx, tree decl, bool copyprivate)
 	    return false;
 	  return (n->value & GOVD_SHARED) == 0;
 	}
+
+      if (ctx->region_type == ORT_WORKSHARE
+	  || ctx->region_type == ORT_TASKGROUP
+	  || ctx->region_type == ORT_SIMD
+	  || ctx->region_type == ORT_ACC)
+	continue;
+
+      break;
     }
-  while (ctx->region_type == ORT_WORKSHARE
-	 || ctx->region_type == ORT_TASKGROUP
-	 || ctx->region_type == ORT_SIMD
-	 || ctx->region_type == ORT_ACC);
+  while (1);
   return false;
 }
 
diff --git a/gcc/testsuite/c-c++-common/gomp/pr101535-1.c b/gcc/testsuite/c-c++-common/gomp/pr101535-1.c
new file mode 100644
index 00000000000..8285ce011df
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/pr101535-1.c
@@ -0,0 +1,31 @@
+/* PR middle-end/101535 */
+
+void
+foo (void)
+{
+  int a = 1, i;
+  #pragma omp target data map(to:a)
+  #pragma omp for lastprivate(i)	/* { dg-error "lastprivate variable 'i' is private in outer context" } */
+  for (i = 1; i < 2; i++)
+    ;
+}
+
+void
+bar (void)
+{
+  int a = 1, i;
+  #pragma omp target private(i)
+  #pragma omp for lastprivate(i)	/* { dg-error "lastprivate variable 'i' is private in outer context" } */
+  for (i = 1; i < 2; i++)
+    ;
+}
+
+void
+baz (void)
+{
+  int a = 1, i;
+  #pragma omp target firstprivate(i)
+  #pragma omp for lastprivate(i)	/* { dg-error "lastprivate variable 'i' is private in outer context" } */
+  for (i = 1; i < 2; i++)
+    ;
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/pr101535-2.c b/gcc/testsuite/c-c++-common/gomp/pr101535-2.c
new file mode 100644
index 00000000000..23c84af4879
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/pr101535-2.c
@@ -0,0 +1,11 @@
+/* PR middle-end/101535 */
+
+void
+foo (void)
+{
+  int a = 1, i;
+  #pragma omp target map(tofrom:i)
+  #pragma omp for lastprivate(i)
+  for (i = 1; i < 2; i++)
+    ;
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-10  8:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-10  8:20 [gcc r10-10637] openmp: Fix up omp_check_private [PR101535] Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).