Bug 58410 - [4.8/4.9 Regression] Bogus uninitialized variable warning for allocatable derived type array function result
Summary: [4.8/4.9 Regression] Bogus uninitialized variable warning for allocatable der...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.8.0
: P4 normal
Target Milestone: 4.8.3
Assignee: Paul Thomas
URL:
Keywords: diagnostic
Depends on:
Blocks: Wuninitialized
  Show dependency treegraph
 
Reported: 2013-09-13 08:47 UTC by Vladimir Fuka
Modified: 2014-01-19 18:07 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-09-15 00:00:00


Attachments
uninit.f90 (234 bytes, text/x-fortran)
2013-09-13 08:48 UTC, Vladimir Fuka
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir Fuka 2013-09-13 08:47:39 UTC
gfortran  -c -Wall -O2 uninit.f90 
uninit.f90: In function ‘sub’:
uninit.f90:22:0: warning: ‘new.dim[0].ubound’ may be used uninitialized in this function [-Wmaybe-uninitialized]
         new = fun()
 ^


gfortran  -c -Wall -O1 uninit.f90
without warning




gfortran  -v
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/local/gcc-4.8/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-4.8-20130509/configure --enable-languages=c,c++,fortran --with-cloog --prefix=/usr/local/gcc-4.8
Thread model: posix
gcc version 4.8.1 20130509 (prerelease) (GCC)
Comment 1 Vladimir Fuka 2013-09-13 08:48:21 UTC
Created attachment 30815 [details]
uninit.f90
Comment 2 janus 2013-09-15 22:01:55 UTC
Confirmed with 4.8 and trunk. The bogus warning does not seem to appear with 4.7.3.
Comment 3 janus 2013-11-18 19:28:02 UTC
Slightly reduced test case:


module m
  implicit none
  
  type series
    real,allocatable :: a(:)
  end type

  contains
  
    function fun()
      type(series),allocatable :: fun(:)
      allocate(fun(0))
    end function
  
    subroutine sub
      type(series),allocatable :: new(:)
      integer :: j
      do j=1,2
        new = fun()
      end do
    end subroutine

end module
Comment 4 Paul Thomas 2013-11-30 18:47:54 UTC
This is not a serious regression and so I have set it to P3.

That said, it is a real bug and I am just now regtesting the fix.

Assigning myself.

Paul
Comment 5 Paul Thomas 2013-12-01 11:42:28 UTC
Author: pault
Date: Sun Dec  1 11:42:25 2013
New Revision: 205566

URL: http://gcc.gnu.org/viewcvs?rev=205566&root=gcc&view=rev
Log:
2013-12-01  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/58410
	* trans-array.c (gfc_alloc_allocatable_for_assignment): Do not
	use the array bounds of an unallocated array but set its size
	to zero instead.

Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-array.c
Comment 6 Paul Thomas 2014-01-19 18:04:54 UTC
Author: pault
Date: Sun Jan 19 18:04:22 2014
New Revision: 206778

URL: http://gcc.gnu.org/viewcvs?rev=206778&root=gcc&view=rev
Log:
2014-01-19  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/58410
	* trans-array.c (gfc_alloc_allocatable_for_assignment): Do not
	use the array bounds of an unallocated array but set its size
	to zero instead.

Modified:
    branches/gcc-4_8-branch/gcc/fortran/ChangeLog
    branches/gcc-4_8-branch/gcc/fortran/trans-array.c
Comment 7 Paul Thomas 2014-01-19 18:07:02 UTC
Fixed on trunk and 4.8.

Thanks for the report

Paul