This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/83344] Use of uninitialized memory with ASSOCIATE and strings


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

--- Comment #8 from Steve Kargl <sgk at troutmask dot apl.washington.edu> ---
On Tue, Dec 12, 2017 at 08:04:54PM +0000, sgk at troutmask dot
apl.washington.edu wrote:
> 
>   /* Fix up the type-spec for CHARACTER types.  */
>   if (sym->ts.type == BT_CHARACTER && !sym->attr.select_type_temporary)
>     {
>       if (!sym->ts.u.cl)
>         sym->ts.u.cl = target->ts.u.cl;
> 
>       if (!sym->ts.u.cl->length && !sym->ts.deferred)
>         sym->ts.u.cl->length
>           = gfc_get_int_expr (gfc_default_integer_kind,
>                               NULL, target->value.character.length);
>     }
> 

So, if I wrap the above code in #if 0 ... #endif.  I sort of
get what I expect.  For the reduce code,

program foo
   implicit none
   character(len=3) a
   a = 'abc';
   call bah(a)
   contains
      subroutine bah(x)
         implicit none
         character(len=*), intent(in) :: x
         print *, x, len(x)
         associate(y => x)
            print *, y, len(y)
         end associate
      end subroutine bah
end program foo

I get the dump-tree-original (with dt_param stuff removed) of

bah (character(kind=1)[1:_x] & restrict x, integer(kind=4) _x,
 character(kind=1)[1:_x] * y)
{
  {
    integer(kind=4) _x = integer(kind=4);
    character(kind=1)[1:_x] * y;

    {
      _gfortran_transfer_character_write (&dt_parm.0, x, _x);
      {
        integer(kind=4) D.3717;
        D.3717 = _x;
        _gfortran_transfer_integer_write (&dt_parm.0, &D.3717, 4);
      }
    }

    y = (character(kind=1)[1:_x] *) x;
    {
      _gfortran_transfer_character_write (&dt_parm.1, y, _x);
      {
        integer(kind=4) D.3721;
        D.3721 = _x;
        _gfortran_transfer_integer_write (&dt_parm.1, &D.3721, 4);
      }
    }
  }
}

It is not at all clear to me why y is passed as a hidden
argument to bah().  The dump looks reasonable with the use
of _x, the hidden length for the assumed length x. It 
also appears that y is treated as a pointer to x, but not
referenced that way in _gfortran_transfer_character_write.

However, I get

% gfcx -o z a.f90
during RTL pass: expand
a.f90:7:0:

       subroutine bah(x)

internal compiler error: in set_parm_default_def_partition, at
tree-ssa-coalesce.c:1919
0x5faa24 set_parm_default_def_partition
        ../../gcc/gcc/tree-ssa-coalesce.c:1919
0xc15987 for_all_parms
        ../../gcc/gcc/tree-ssa-coalesce.c:1023
0xc16608 get_parm_default_def_partitions(_var_map*)
        ../../gcc/gcc/tree-ssa-coalesce.c:1936
0xbcde40 remove_ssa_form
        ../../gcc/gcc/tree-outof-ssa.c:971
0xbcde40 rewrite_out_of_ssa(ssaexpand*)
        ../../gcc/gcc/tree-outof-ssa.c:1174
0x829cc0 execute
        ../../gcc/gcc/cfgexpand.c:6180
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]