[Bug fortran/90741] Unreachable second '__builtin_malloc' for scalar 'allocatable'

kargl at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Jun 4 16:50:00 GMT 2019


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

kargl at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kargl at gcc dot gnu.org

--- Comment #2 from kargl at gcc dot gnu.org ---
(In reply to Jakub Jelinek from comment #1)
> The first malloc call is from expansion of allocate statement, while the
> second one is for the a = 50 assignment which must allocate on the
> assignment if not allocated already.  I don't see any bug.

Jakub is correct here.  Fortran has (re)allocation on assignment.
You can disable the (re)allocation with the -fno-realloc-lhs option.

This simple code

% cat a.f90
program foo
   integer, allocatable :: i
   allocate(i)
   i = 42
end program foo

compiled with

%  gfcx -c -fdump-tree-original -fno-realloc-lhs a.f90

yields (shortening error messages for brevity)

{
  integer(kind=4) * i;

  i = 0B;
  if (i != 0B)
    {
      _gfortran_runtime_error_at ("Attempting to allocate ...");
    }
  else
    {
      i = (integer(kind=4) *) __builtin_malloc (4);
      if (i == 0B)
        {
          _gfortran_os_error ("exceed memory limit");
        }
    }
  *i = 42;
}


More information about the Gcc-bugs mailing list