public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed] Avoid -W*ununitialized warnings with OpenMP privatized allocatables (PR fortran/89651)
@ 2019-03-11 22:30 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2019-03-11 22:30 UTC (permalink / raw)
  To: gcc-patches; +Cc: fortran

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

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

only message in thread, other threads:[~2019-03-11 22:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-11 22:30 [committed] Avoid -W*ununitialized warnings with OpenMP privatized allocatables (PR fortran/89651) 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).