From 879287d96b5a37c7cc167ad792ac795075a457fd Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 11 Feb 2014 21:48:26 +0100 Subject: [PATCH] re PR fortran/52370 (Spurious "may be used uninitialized" warning for check of optional argument) 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. From-SVN: r207698 --- gcc/fortran/ChangeLog | 6 ++++++ gcc/fortran/trans-decl.c | 4 ++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/pr52370.f90 | 21 +++++++++++++++++++++ 4 files changed, 36 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/pr52370.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 89b34abff0f..c625a70e9e9 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2014-02-11 Jakub Jelinek + + PR fortran/52370 + * trans-decl.c (gfc_build_dummy_array_decl): Set TREE_NO_WARNING + on decl if sym->attr.optional. + 2014-02-09 Paul Thomas PR fortran/57522 diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index bb02f43381f..9c86653e22e 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -1014,6 +1014,10 @@ gfc_build_dummy_array_decl (gfc_symbol * sym, tree dummy) 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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6d3743afddb..b9a4cd15b0b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-02-11 Jakub Jelinek + + PR fortran/52370 + * gfortran.dg/pr52370.f90: New test. + 2014-02-11 Uros Bizjak PR target/59927 diff --git a/gcc/testsuite/gfortran.dg/pr52370.f90 b/gcc/testsuite/gfortran.dg/pr52370.f90 new file mode 100644 index 00000000000..66a6fe2b80d --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr52370.f90 @@ -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