http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47674

           Summary: gfortran.dg/realloc_on_assign_5.f03: Segfault at run
                    time
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: bur...@gcc.gnu.org
                CC: pa...@gcc.gnu.org


gfortran.dg/realloc_on_assign_5.f03 segfaults here; it works if I unset the
environment variable MALLOC_CHECK_.

Valgrind shows:

Invalid read of size 1
   at 0x4C285C8: memmove (in
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x400B41: MAIN__ (realloc_on_assign_5.f03:15)
   by 0x400BF7: main (realloc_on_assign_5.f03:18)
Address 0x5b524c1 is 0 bytes after a block of size 1 alloc'd
   at 0x4C26682: realloc (in
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x400B0C: MAIN__ (realloc_on_assign_5.f03:15)
   by 0x400BF7: main (realloc_on_assign_5.f03:18)

Excerpt from the test:
  a = 'ab'   ! OK
  a = (a(2:2)) ! seems to fail
thus
  print '(">",a,"<")', a
prints ">", STX (start of text character), "<" and a new line. Without
MALLOC_CHECK_ the desired ">b<" and a new line is printed.


DUMP: The first "if" does not make sense - at least in this special case - and
there is the issue that "a" is also used on the RHS without using a temporary.

        D.1531 = .a;
        if (D.1531 != 0)
          {
            if ((<unnamed-unsigned:64>) D.1531 <= 1)
              {
                __builtin_memmove (a, &(*a)[2]{lb: 1 sz: 1}, D.1531);
              }
            else
              {
                __builtin_memcpy (a, &(*a)[2]{lb: 1 sz: 1}, 1);
                __builtin_memset (a + 1, 32, D.1531 + 0x0ffffffffffffffff);
              }
          }

Reply via email to