re PR fortran/89651 (OpenMP private array uninitialized warning with -O flag)
authorJakub Jelinek <jakub@redhat.com>
Mon, 11 Mar 2019 22:27:39 +0000 (23:27 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 11 Mar 2019 22:27:39 +0000 (23:27 +0100)
PR fortran/89651
* trans-openmp.c (gfc_omp_clause_default_ctor): Set TREE_NO_WARNING
on decl if adding COND_EXPR for allocatable.
(gfc_omp_clause_copy_ctor): Set TREE_NO_WARNING on dest.

* gfortran.dg/gomp/pr89651.f90: New test.

From-SVN: r269598

gcc/fortran/ChangeLog
gcc/fortran/trans-openmp.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/gomp/pr89651.f90 [new file with mode: 0644]

index 1c738baedaa1c3c301757c49597120c7d17983e7..a3b47ac4980130750ebbe95203bbc77f8b6f0d26 100644 (file)
@@ -1,3 +1,10 @@
+2019-03-11  Jakub Jelinek  <jakub@redhat.com>
+
+       PR fortran/89651
+       * trans-openmp.c (gfc_omp_clause_default_ctor): Set TREE_NO_WARNING
+       on decl if adding COND_EXPR for allocatable.
+       (gfc_omp_clause_copy_ctor): Set TREE_NO_WARNING on dest.
+
 2019-03-11  Martin Liska  <mliska@suse.cz>
 
        * decl.c (match_record_decl): Wrap an option name
index 1fdb70e9bd8dd14ce0b3ad46ae3741735ce2c0ac..0eb5956cc5313b97a17ebdbddec3d85b0a2148d9 100644 (file)
@@ -558,6 +558,9 @@ gfc_omp_clause_default_ctor (tree clause, tree decl, tree outer)
                             build3_loc (input_location, COND_EXPR,
                                         void_type_node, cond, then_b,
                                         else_b));
+      /* Avoid -W*uninitialized warnings.  */
+      if (DECL_P (decl))
+       TREE_NO_WARNING (decl) = 1;
     }
   else
     gfc_add_expr_to_block (&block, then_b);
@@ -664,6 +667,9 @@ gfc_omp_clause_copy_ctor (tree clause, tree dest, tree src)
   gfc_add_expr_to_block (&block,
                         build3_loc (input_location, COND_EXPR,
                                     void_type_node, cond, then_b, else_b));
+  /* Avoid -W*uninitialized warnings.  */
+  if (DECL_P (dest))
+    TREE_NO_WARNING (dest) = 1;
 
   return gfc_finish_block (&block);
 }
index fdc7c40e4502d889f3551ae821e4c176d1078a55..8c992a8ed421bebf6a51aea5299b8571d6d74c95 100644 (file)
@@ -1,5 +1,8 @@
 2019-03-11  Jakub Jelinek  <jakub@redhat.com>
 
+       PR fortran/89651
+       * gfortran.dg/gomp/pr89651.f90: New test.
+
        PR middle-end/89655
        PR bootstrap/89656
        * gcc.c-torture/compile/pr89655.c: New test.
diff --git a/gcc/testsuite/gfortran.dg/gomp/pr89651.f90 b/gcc/testsuite/gfortran.dg/gomp/pr89651.f90
new file mode 100644 (file)
index 0000000..b5054fd
--- /dev/null
@@ -0,0 +1,21 @@
+! PR fortran/89651
+! { dg-do compile }
+! { dg-additional-options "-Wuninitialized" }
+
+program pr89651
+  integer :: n
+  real, allocatable :: t(:)
+  n = 10
+  allocate (t(n), source = 0.0)
+!$omp parallel firstprivate(t)
+  print *, sum (t) ! { dg-bogus "lbound' may be used uninitialized in this function" }
+                   ! { dg-bogus "ubound' may be used uninitialized in this function" "" { target *-*-* } .-1 }
+                   ! { dg-bogus "offset' may be used uninitialized in this function" "" { target *-*-* } .-2 }
+!$omp end parallel
+!$omp parallel private(t)
+  t = 0.0
+  print *, sum (t) ! { dg-bogus "lbound' may be used uninitialized in this function" }
+                   ! { dg-bogus "ubound' may be used uninitialized in this function" "" { target *-*-* } .-1 }
+                   ! { dg-bogus "offset' may be used uninitialized in this function" "" { target *-*-* } .-2 }
+!$omp end parallel
+end program pr89651