[PATCH] Avoid uninit warnings with Fortran optional args (PR fortran/52370)
Jakub Jelinek
jakub@redhat.com
Tue Feb 11 20:38:00 GMT 2014
Hi!
Optional dummy arg support vars are often undefined in various paths,
while the predicated uninit analysis can sometimes avoid false positives,
sometimes it can't. So IMHO we should set TREE_NO_WARNING here, it is
already set on the other support vars like size.N, ubound.N, lbound.N, etc.
but not on the actual data pointer.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2014-02-11 Jakub Jelinek <jakub@redhat.com>
PR fortran/52370
* trans-decl.c (gfc_build_dummy_array_decl): Set TREE_NO_WARNING
on decl if sym->attr.optional.
* gfortran.dg/pr52370.f90: New test.
--- gcc/fortran/trans-decl.c.jj 2014-01-03 11:40:53.000000000 +0100
+++ gcc/fortran/trans-decl.c 2014-02-11 18:17:47.315598566 +0100
@@ -1014,6 +1014,10 @@ gfc_build_dummy_array_decl (gfc_symbol *
TREE_STATIC (decl) = 0;
DECL_EXTERNAL (decl) = 0;
+ /* Avoid uninitialized warnings for optional dummy arguments. */
+ if (sym->attr.optional)
+ TREE_NO_WARNING (decl) = 1;
+
/* We should never get deferred shape arrays here. We used to because of
frontend bugs. */
gcc_assert (sym->as->type != AS_DEFERRED);
--- gcc/testsuite/gfortran.dg/pr52370.f90.jj 2014-02-11 18:20:45.704628460 +0100
+++ gcc/testsuite/gfortran.dg/pr52370.f90 2014-02-11 18:20:11.000000000 +0100
@@ -0,0 +1,21 @@
+! PR fortran/52370
+! { dg-do compile }
+! { dg-options "-O1 -Wall" }
+
+module pr52370
+contains
+ subroutine foo(a,b)
+ real, intent(out) :: a
+ real, dimension(:), optional, intent(out) :: b
+ a=0.5
+ if (present(b)) then
+ b=1.0
+ end if
+ end subroutine foo
+end module pr52370
+
+program prg52370
+ use pr52370
+ real :: a
+ call foo(a)
+end program prg52370
Jakub
More information about the Fortran
mailing list