re PR middle-end/70550 (-Wuninitialized false positives in OpenMP code)
authorJakub Jelinek <jakub@redhat.com>
Wed, 6 Apr 2016 12:42:24 +0000 (14:42 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 6 Apr 2016 12:42:24 +0000 (14:42 +0200)
PR middle-end/70550
* tree.h (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT): Define.
* gimplify.c (gimplify_adjust_omp_clauses_1): Set it for implicit
firstprivate clauses.
* omp-low.c (lower_send_clauses): Set TREE_NO_WARNING for
OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT !by_ref vars in task contexts.
(lower_omp_target): Set TREE_NO_WARNING for
non-addressable possibly uninitialized vars which are copied into
addressable temporaries or copied for GOMP_MAP_FIRSTPRIVATE_INT.

* c-c++-common/gomp/pr70550-1.c: New test.
* c-c++-common/gomp/pr70550-2.c: New test.

From-SVN: r234779

gcc/ChangeLog
gcc/gimplify.c
gcc/omp-low.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/gomp/pr70550-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/pr70550-2.c [new file with mode: 0644]
gcc/tree.h

index d0ae429b49d989cf25ee12a974184c58662db5a6..e31d7cfff05d0ad67018fd16672e4179e82dc347 100644 (file)
@@ -1,3 +1,15 @@
+2016-04-06  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/70550
+       * tree.h (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT): Define.
+       * gimplify.c (gimplify_adjust_omp_clauses_1): Set it for implicit
+       firstprivate clauses.
+       * omp-low.c (lower_send_clauses): Set TREE_NO_WARNING for
+       OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT !by_ref vars in task contexts.
+       (lower_omp_target): Set TREE_NO_WARNING for
+       non-addressable possibly uninitialized vars which are copied into
+       addressable temporaries or copied for GOMP_MAP_FIRSTPRIVATE_INT.
+
 2016-04-05  John David Anglin  <danglin@gcc.gnu.org>
 
        * config/pa/predicates.md (integer_store_memory_operand): Accept
index b9757db4c893f64c5766662daf19439b2c9b5cdc..f29d608f5eb9ea45ec56c30f08111ff2c390b8cf 100644 (file)
@@ -7742,6 +7742,8 @@ gimplify_adjust_omp_clauses_1 (splay_tree_node n, void *data)
           && (flags & GOVD_WRITTEN) == 0
           && omp_shared_to_firstprivate_optimizable_decl_p (decl))
     OMP_CLAUSE_SHARED_READONLY (clause) = 1;
+  else if (code == OMP_CLAUSE_FIRSTPRIVATE && (flags & GOVD_EXPLICIT) == 0)
+    OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (clause) = 1;
   else if (code == OMP_CLAUSE_MAP && (flags & GOVD_MAP_0LEN_ARRAY) != 0)
     {
       tree nc = build_omp_clause (input_location, OMP_CLAUSE_MAP);
index 3fd6eb304b662705dab4047d354f3c11d6b4014e..52a80059ef344b685977fc7fc30dc8bd8a911a62 100644 (file)
@@ -6107,8 +6107,15 @@ lower_send_clauses (tree clauses, gimple_seq *ilist, gimple_seq *olist,
 
       switch (OMP_CLAUSE_CODE (c))
        {
-       case OMP_CLAUSE_PRIVATE:
        case OMP_CLAUSE_FIRSTPRIVATE:
+         if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
+             && !by_ref
+             && is_task_ctx (ctx))
+           TREE_NO_WARNING (var) = 1;
+         do_in = true;
+         break;
+
+       case OMP_CLAUSE_PRIVATE:
        case OMP_CLAUSE_COPYIN:
        case OMP_CLAUSE__LOOPTEMP_:
          do_in = true;
@@ -16083,7 +16090,16 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx)
                        || map_kind == GOMP_MAP_POINTER
                        || map_kind == GOMP_MAP_TO_PSET
                        || map_kind == GOMP_MAP_FORCE_DEVICEPTR)
-                     gimplify_assign (avar, var, &ilist);
+                     {
+                       /* If we need to initialize a temporary
+                          with VAR because it is not addressable, and
+                          the variable hasn't been initialized yet, then
+                          we'll get a warning for the store to avar.
+                          Don't warn in that case, the mapping might
+                          be implicit.  */
+                       TREE_NO_WARNING (var) = 1;
+                       gimplify_assign (avar, var, &ilist);
+                     }
                    avar = build_fold_addr_expr (avar);
                    gimplify_assign (x, avar, &ilist);
                    if ((GOMP_MAP_COPY_FROM_P (map_kind)
@@ -16252,6 +16268,8 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx)
                tree t = var;
                if (is_reference (var))
                  t = build_simple_mem_ref (var);
+               else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c))
+                 TREE_NO_WARNING (var) = 1;
                if (TREE_CODE (type) != POINTER_TYPE)
                  t = fold_convert (pointer_sized_int_node, t);
                t = fold_convert (TREE_TYPE (x), t);
@@ -16263,6 +16281,8 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx)
              {
                tree avar = create_tmp_var (TREE_TYPE (var));
                mark_addressable (avar);
+               if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c))
+                 TREE_NO_WARNING (var) = 1;
                gimplify_assign (avar, var, &ilist);
                avar = build_fold_addr_expr (avar);
                gimplify_assign (x, avar, &ilist);
index 2e5954ca8ac8a592487eb846bb1a5057fd0083ae..5c4b95f9381fe7b01b5eb695d31faa89a0b0fbb8 100644 (file)
@@ -1,3 +1,9 @@
+2016-04-06  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/70550
+       * c-c++-common/gomp/pr70550-1.c: New test.
+       * c-c++-common/gomp/pr70550-2.c: New test.
+
 2016-04-05  Nathan Sidwell  <nathan@acm.org>
 
        PR c++/70512
diff --git a/gcc/testsuite/c-c++-common/gomp/pr70550-1.c b/gcc/testsuite/c-c++-common/gomp/pr70550-1.c
new file mode 100644 (file)
index 0000000..493d417
--- /dev/null
@@ -0,0 +1,81 @@
+/* PR middle-end/70550 */
+/* { dg-do compile } */
+/* { dg-additional-options "-Wuninitialized" } */
+
+#ifdef __SIZEOF_INT128__
+typedef __int128 T;
+#else
+typedef long long T;
+#endif
+
+void bar (T);
+#pragma omp declare target (bar)
+
+void
+foo (void)
+{
+  {
+    int i;
+    #pragma omp target defaultmap(tofrom:scalar)       /* { dg-bogus "is used uninitialized in this function" } */
+    {
+      i = 26;
+      bar (i);
+    }
+  }
+  {
+    T j;
+    #pragma omp target defaultmap(tofrom:scalar)       /* { dg-bogus "is used uninitialized in this function" } */
+    {
+      j = 37;
+      bar (j);
+    }
+  }
+  {
+    int i;
+    #pragma omp target                                 /* { dg-bogus "is used uninitialized in this function" } */
+    {
+      i = 26;
+      bar (i);
+    }
+  }
+  {
+    T j;
+    #pragma omp target                                 /* { dg-bogus "is used uninitialized in this function" } */
+    {
+      j = 37;
+      bar (j);
+    }
+  }
+  {
+    int i;
+    #pragma omp target firstprivate (i)                        /* { dg-warning "is used uninitialized in this function" } */
+    {
+      i = 26;
+      bar (i);
+    }
+  }
+  {
+    T j;
+    #pragma omp target firstprivate (j)                        /* { dg-warning "is used uninitialized in this function" } */
+    {
+      j = 37;
+      bar (j);
+    }
+  }
+  {
+    int i;
+    #pragma omp target private (i)                     /* { dg-bogus "is used uninitialized in this function" } */
+    {
+      i = 26;
+      bar (i);
+    }
+  }
+  {
+    T j;
+    #pragma omp target private (j)                     /* { dg-bogus "is used uninitialized in this function" } */
+    {
+      j = 37;
+      bar (j);
+    }
+  }
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/pr70550-2.c b/gcc/testsuite/c-c++-common/gomp/pr70550-2.c
new file mode 100644 (file)
index 0000000..31c34da
--- /dev/null
@@ -0,0 +1,55 @@
+/* PR middle-end/70550 */
+/* { dg-do compile } */
+/* { dg-additional-options "-Wuninitialized" } */
+
+void bar (int);
+
+void
+foo (void)
+{
+  int i, j, k, l, m, n, o, p, q;
+  #pragma omp task                             /* { dg-bogus "is used uninitialized in this function" } */
+  {
+    i = 2;
+    bar (i);
+  }
+  #pragma omp taskloop                         /* { dg-bogus "is used uninitialized in this function" } */
+  for (j = 0; j < 10; j++)
+    {
+      k = 7;
+      bar (k);
+    }
+  #pragma omp task firstprivate (l)            /* { dg-warning "is used uninitialized in this function" } */
+  {
+    l = 2;
+    bar (l);
+  }
+  #pragma omp taskloop firstprivate (m)                /* { dg-warning "is used uninitialized in this function" } */
+  for (j = 0; j < 10; j++)
+    {
+      m = 7;
+      bar (m);
+    }
+  #pragma omp task shared (n)                  /* { dg-bogus "is used uninitialized in this function" } */
+  {
+    n = 2;
+    bar (n);
+  }
+  #pragma omp taskloop shared (o)              /* { dg-bogus "is used uninitialized in this function" } */
+  for (j = 0; j < 10; j++)
+    {
+      o = 7;
+      bar (o);
+    }
+  #pragma omp task private (p)                 /* { dg-bogus "is used uninitialized in this function" } */
+  {
+    p = 2;
+    bar (p);
+  }
+  #pragma omp taskloop shared (q)              /* { dg-bogus "is used uninitialized in this function" } */
+  for (j = 0; j < 10; j++)
+    {
+      q = 7;
+      bar (q);
+    }
+}
index 544a6a163dfc146e631e7734e673b5dd60750593..fa705967e13df4d01a96d2b40c819ae5bb2dbdf6 100644 (file)
@@ -1430,6 +1430,10 @@ extern void protected_set_expr_location (tree, location_t);
 #define OMP_CLAUSE_PRIVATE_TASKLOOP_IV(NODE) \
   TREE_PROTECTED (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_PRIVATE))
 
+/* True on a FIRSTPRIVATE clause if it has been added implicitly.  */
+#define OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT(NODE) \
+  (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_FIRSTPRIVATE)->base.public_flag)
+
 /* True on a LASTPRIVATE clause if a FIRSTPRIVATE clause for the same
    decl is present in the chain.  */
 #define OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE(NODE) \