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 #9 from Janne Blomqvist <jb at gcc dot gnu.org> ---
With the patch in #2 (which in this case is equivalent to your patch in #8) I
get on my charlen->size_t branch:

❯ gfortran -O0 -Wall -c a22.f90
a22.f90:20:0:

   associate(w4 => trim(s))

Warning: ‘.w4’ is used uninitialized in this function [-Wuninitialized]
a22.f90:20:0:

   associate(w4 => trim(s))

Error: size of variable ‘w4’ is too large


The warning is entirely correct, if one looks at the 003t.original dump one can
see that .w4 is never assigned to:

foo ()
{
  character(kind=1) s[1:4];

  {
    integer(kind=8) .w4;
    character(kind=1) w4[1:.w4];

    {
      character(kind=1) * pstr.0;
      integer(kind=8) len.1;
      sizetype D.3727;
      sizetype D.3728;

      _gfortran_string_trim (&len.1, (void * *) &pstr.0, 4, &s);
      D.3727 = (sizetype) len.1;
      D.3728 = (sizetype) .w4;
      if (D.3728 != 0)
        {
          __builtin_memmove ((void *) &w4, (void *) pstr.0, (unsigned long)
MIN_EXPR <NON_LVALUE_EXPR <D.3728>, NON_LVALUE_EXPR <D.3727>>);
          if (NON_LVALUE_EXPR <D.3727> < NON_LVALUE_EXPR <D.3728>)
            {
              __builtin_memset ((void *) &w4 + NON_LVALUE_EXPR <D.3727>, 32,
(unsigned long) (NON_LVALUE_EXPR <D.3728> - NON_LVALUE_EXPR <D.3727>));
            }
        }
      if (len.1 > 0)
        {
          __builtin_free ((void *) pstr.0);
        }
    }
    L.1:;
  }
}

What the "w4 is too large" error message means I'm not sure. It might be that
the uninitialized kind=8 .w4 value is large enough to trigger some kind of
"this must be non-sensical" error in the middle-end.

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