re PR middle-end/27416 (ICE on invalid firstprivate/lastprivate)
authorJakub Jelinek <jakub@redhat.com>
Wed, 24 Jan 2007 20:58:21 +0000 (21:58 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 24 Jan 2007 20:58:21 +0000 (21:58 +0100)
PR middle-end/27416
* gimplify.c (omp_check_private): New function.
(gimplify_scan_omp_clauses): Use it for
firstprivate/lastprivate/reduction.

* gcc.dg/gomp/pr27416.c: New test.

From-SVN: r121133

gcc/ChangeLog
gcc/gimplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/gomp/pr27416.c [new file with mode: 0644]

index 8d5d41189c3b46996f51c1775cdbeee19b9d2bf7..f9b788ce9ea82cd2e669910bd3bd037e6c918076 100644 (file)
@@ -1,5 +1,10 @@
 2007-01-24  Jakub Jelinek  <jakub@redhat.com>
 
+       PR middle-end/27416
+       * gimplify.c (omp_check_private): New function.
+       (gimplify_scan_omp_clauses): Use it for
+       firstprivate/lastprivate/reduction.
+
        PR middle-end/30494
        * gimplify.c (omp_add_variable): Don't call omp_notice_variable
        on TYPE_SIZE_UNIT for GOVD_LOCAL VLAs.
index be02fb23cbb3d36007b0ee7df9ecaa444a94b2df..19323ae59c3a347238c9f09c9192acd65d8493fc 100644 (file)
@@ -4667,6 +4667,31 @@ omp_is_private (struct gimplify_omp_ctx *ctx, tree decl)
     return !is_global_var (decl);
 }
 
+/* Return true if DECL is private within a parallel region
+   that binds to the current construct's context or in parallel
+   region's REDUCTION clause.  */
+
+static bool
+omp_check_private (struct gimplify_omp_ctx *ctx, tree decl)
+{
+  splay_tree_node n;
+
+  do
+    {
+      ctx = ctx->outer_context;
+      if (ctx == NULL)
+       return !(is_global_var (decl)
+                /* References might be private, but might be shared too.  */
+                || lang_hooks.decls.omp_privatize_by_reference (decl));
+
+      n = splay_tree_lookup (ctx->variables, (splay_tree_key) decl);
+      if (n != NULL)
+       return (n->value & GOVD_SHARED) == 0;
+    }
+  while (!ctx->is_parallel);
+  return false;
+}
+
 /* Scan the OpenMP clauses in *LIST_P, installing mappings into a new
    and previous omp contexts.  */
 
@@ -4685,6 +4710,7 @@ gimplify_scan_omp_clauses (tree *list_p, tree *pre_p, bool in_parallel,
       enum gimplify_status gs;
       bool remove = false;
       bool notice_outer = true;
+      const char *check_non_private = NULL;
       unsigned int flags;
       tree decl;
 
@@ -4699,12 +4725,15 @@ gimplify_scan_omp_clauses (tree *list_p, tree *pre_p, bool in_parallel,
          goto do_add;
        case OMP_CLAUSE_FIRSTPRIVATE:
          flags = GOVD_FIRSTPRIVATE | GOVD_EXPLICIT;
+         check_non_private = "firstprivate";
          goto do_add;
        case OMP_CLAUSE_LASTPRIVATE:
          flags = GOVD_LASTPRIVATE | GOVD_SEEN | GOVD_EXPLICIT;
+         check_non_private = "lastprivate";
          goto do_add;
        case OMP_CLAUSE_REDUCTION:
          flags = GOVD_REDUCTION | GOVD_SEEN | GOVD_EXPLICIT;
+         check_non_private = "reduction";
          goto do_add;
 
        do_add:
@@ -4754,6 +4783,14 @@ gimplify_scan_omp_clauses (tree *list_p, tree *pre_p, bool in_parallel,
        do_notice:
          if (outer_ctx)
            omp_notice_variable (outer_ctx, decl, true);
+         if (check_non_private
+             && !in_parallel
+             && omp_check_private (ctx, decl))
+           {
+             error ("%s variable %qs is private in outer context",
+                    check_non_private, IDENTIFIER_POINTER (DECL_NAME (decl)));
+             remove = true;
+           }
          break;
 
        case OMP_CLAUSE_IF:
index fcb4e7442a6aec773a63946bd4c0ccc8efd93b92..3f42ce95963ea2c46f9982a082301a9f36256f6f 100644 (file)
@@ -1,5 +1,8 @@
 2007-01-24  Jakub Jelinek  <jakub@redhat.com>
 
+       PR middle-end/27416
+       * gcc.dg/gomp/pr27416.c: New test.
+
        PR middle-end/30494
        * gcc.dg/gomp/pr30494.c: New test.
        * g++.dg/gomp/pr30494.C: New test.
diff --git a/gcc/testsuite/gcc.dg/gomp/pr27416.c b/gcc/testsuite/gcc.dg/gomp/pr27416.c
new file mode 100644 (file)
index 0000000..8024024
--- /dev/null
@@ -0,0 +1,31 @@
+/* PR middle-end/27416 */
+/* { dg-do compile } */
+
+void
+foo (void)
+{
+  int i = 0, j = 0;
+#pragma omp for firstprivate (j) /* { dg-error "is private in outer context" } */
+  for (i = 0; i < 10; i++)
+    j++;
+}
+
+int
+bar (void)
+{
+  int i, j;
+#pragma omp for lastprivate (j)        /* { dg-error "is private in outer context" } */
+  for (i = 0; i < 10; i++)
+    j = i;
+  return j;
+}
+
+int
+baz (void)
+{
+  int i, j = 0;
+#pragma omp for reduction (+:j)        /* { dg-error "is private in outer context" } */
+  for (i = 0; i < 10; i++)
+    j++;
+  return j;
+}