[Bug fortran/100440] allocated() gives True for unallocated variable

sgk at troutmask dot apl.washington.edu gcc-bugzilla@gcc.gnu.org
Fri May 7 21:58:10 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100440

--- Comment #7 from Steve Kargl <sgk at troutmask dot apl.washington.edu> ---
On Fri, May 07, 2021 at 09:12:15PM +0000, anlauf at gcc dot gnu.org wrote:
> --- Comment #6 from anlauf at gcc dot gnu.org ---
> There seems to be something fishy with default initialization of function
> results of derived types.

There is no default initialization in the code below.  default
initialization is

  type foo
    integer :: i = 1  ! <-- Default initialization
  end tyep foo

> Looking at the attached code, I guessed the
> following potential reproducer:
> 
> program p
>   implicit none
>   type multi
>      real, allocatable :: mp(:)
>   end type
>   type fm
>      type(multi) :: mfm
>   end type
>   type(fm), allocatable :: a(:,:)
>   integer :: n = 1
>   allocate (a(n,n))
>   a = mm (a, a)
>   a = mm (a, a) ! crashes here with -fsanitize=address
> contains
>   function mm (ma, mb)
>     type(fm) :: ma(:,:), mb(:,:)
>     type(fm), dimension(size(ma,dim=1),size(mb,dim=2)) :: mm

So, it is the size(ma,dim=1) and size(mb,dim=2) that are causing
the problem.


More information about the Gcc-bugs mailing list