This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[committed] Avoid -W*ununitialized warnings with OpenMP privatized allocatables (PR fortran/89651)


Hi!

As mentioned in the PR, for the case where the allocatable being privatized
is "not currently allocated", we only clear the data pointer and in code
where the user guarantees in the caller that the original variable is always
allocated, this can result in false positive -Wmaybe-uninitialized warnings.

Worked around following way, bootstrapped/regtested on x86_64-linux and
i686-linux, committed to trunk.

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.

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

--- gcc/fortran/trans-openmp.c.jj	2019-01-16 09:35:08.633255760 +0100
+++ gcc/fortran/trans-openmp.c	2019-03-11 18:09:32.297245296 +0100
@@ -558,6 +558,9 @@ gfc_omp_clause_default_ctor (tree clause
 			     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, t
   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);
 }
--- gcc/testsuite/gfortran.dg/gomp/pr89651.f90.jj	2019-03-11 18:05:37.740066305 +0100
+++ gcc/testsuite/gfortran.dg/gomp/pr89651.f90	2019-03-11 18:07:06.813615269 +0100
@@ -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

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]