Bug 60542 - [4.9 Regression] realloc_on_assign_5.f03 aborts
Summary: [4.9 Regression] realloc_on_assign_5.f03 aborts
Status: RESOLVED DUPLICATE of bug 47674
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: unknown
: P4 normal
Target Milestone: 4.9.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-03-15 17:54 UTC by Thomas Koenig
Modified: 2014-03-16 10:09 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Koenig 2014-03-15 17:54:15 UTC
This is not PR 47674 (or so I think).

ig25@linux-fd1f:~/Krempel/Where> gfortran realloc_on_assign_5.f03 
ig25@linux-fd1f:~/Krempel/Where> ./a.out

Program aborted. Backtrace:
#0  0x7F67C6393417
#1  0x7F67C6394B12
#2  0x7F67C64651C8
#3  0x400C9E in MAIN__ at realloc_on_assign_5.f03:?
Comment 1 Thomas Koenig 2014-03-15 17:54:40 UTC
Janus, do you have any idea?
Comment 2 janus 2014-03-15 18:00:13 UTC
(In reply to Thomas Koenig from comment #1)
> Janus, do you have any idea?

Not without any further info:
 * What OS/configure line?
 * What GCC revision? When did it show up?
 * Can you generate a better backtrace (with -g3 -O0)?
Comment 3 Thomas Koenig 2014-03-15 18:07:30 UTC
This is with current trunk (as of a few minutes ago), on x86_64-unknown-linux-gnu.

ig25@linux-fd1f:~/Krempel/Where> gfortran -g realloc_on_assign_5.f03 
ig25@linux-fd1f:~/Krempel/Where> gfortran -v
Es werden eingebaute Spezifikationen verwendet.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/home/ig25/lib/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper
Ziel: x86_64-unknown-linux-gnu
Konfiguriert mit: ../trunk/configure --prefix=/home/ig25 --enable-languages=c,fortran,c++
Thread-Modell: posix
gcc-Version 4.9.0 20140315 (experimental) (GCC) 
ig25@linux-fd1f:~/Krempel/Where> ./a.out

Program aborted. Backtrace:
#0  0x7F2AC9F1D417
#1  0x7F2AC9F1EB12
#2  0x7F2AC9FEF208
#3  0x400C9E in MAIN__ at realloc_on_assign_5.f03:16 (discriminator 1)
Abgebrochen

gdb tells me this is at

Breakpoint 1, 0x00007ffff6ff2b90 in abort () from /lib64/libc.so.6
(gdb) bt
#0  0x00007ffff6ff2b90 in abort () from /lib64/libc.so.6
#1  0x00007ffff7adbaf9 in _gfortrani_sys_abort () at ../../../trunk/libgfortran/runtime/error.c:173
#2  0x00007ffff7bac209 in _gfortran_abort () at ../../../trunk/libgfortran/intrinsics/abort.c:33
#3  0x0000000000400c9f in MAIN__ () at realloc_on_assign_5.f03:16
(gdb) up
#1  0x00007ffff7adbaf9 in _gfortrani_sys_abort () at ../../../trunk/libgfortran/runtime/error.c:173
173       abort();
(gdb) up
#2  0x00007ffff7bac209 in _gfortran_abort () at ../../../trunk/libgfortran/intrinsics/abort.c:33
33        sys_abort ();
(gdb) up
#3  0x0000000000400c9f in MAIN__ () at realloc_on_assign_5.f03:16
16        if (a .ne. 'x') call abort
Comment 4 janus 2014-03-15 18:22:26 UTC
(In reply to Thomas Koenig from comment #3)
> This is with current trunk (as of a few minutes ago), on
> x86_64-unknown-linux-gnu.

I'm on the same platform and don't see the failure with

gcc version 4.9.0 20140315 (experimental) [trunk revision 208590] (GCC)



> ig25@linux-fd1f:~/Krempel/Where> ./a.out
> 
> Program aborted. Backtrace:
> #0  0x7F2AC9F1D417
> #1  0x7F2AC9F1EB12
> #2  0x7F2AC9FEF208
> #3  0x400C9E in MAIN__ at realloc_on_assign_5.f03:16 (discriminator 1)
> Abgebrochen

So maybe you can try this?

Index: realloc_on_assign_5.f03
===================================================================
--- realloc_on_assign_5.f03	(revision 208590)
+++ realloc_on_assign_5.f03	(working copy)
@@ -13,6 +13,7 @@
   if (a .ne. 'ax') call abort
   if (len (a) .ne. 2) call abort
   a = (a(2:2))
+  print *,a
   if (a .ne. 'x') call abort
   if (len (a) .ne. 1) call abort
 end program main


Maybe you could do a bit of debugging to see what goes wrong and where the error actually comes from?
Comment 5 Thomas Koenig 2014-03-15 23:52:31 UTC
Here's what valgrind has to say:

ig25@linux-fd1f:~/Krempel/Where> cat r.f90
! { dg-do run }
! Test the fix for PR47523 in which concatenations did not work
! correctly with assignments to deferred character length scalars.
!
! Contributed by Thomas Koenig  <tkoenig@gcc.gnu.org>
!
program main
  implicit none
  character(:), allocatable :: a, b
  a = 'a'
  if (a .ne. 'a') call abort
  a = a // 'x'
  if (a .ne. 'ax') call abort
  if (len (a) .ne. 2) call abort
  a = (a(2:2))
  print *,a
  if (a .ne. 'x') call abort
  if (len (a) .ne. 1) call abort
end program main
ig25@linux-fd1f:~/Krempel/Where> gfortran -g r.f90 
ig25@linux-fd1f:~/Krempel/Where> valgrind ./a.out
==27652== Memcheck, a memory error detector
==27652== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==27652== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==27652== Command: ./a.out
==27652== 
==27652== Invalid read of size 1
==27652==    at 0x4C2BD60: memcpy@GLIBC_2.2.5 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==27652==    by 0x400DBE: MAIN__ (r.f90:15)
==27652==    by 0x400EDE: main (r.f90:19)
==27652==  Address 0x5c56521 is 0 bytes after a block of size 1 alloc'd
==27652==    at 0x4C29B7E: realloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==27652==    by 0x400D7A: MAIN__ (r.f90:15)
==27652==    by 0x400EDE: main (r.f90:19)
==27652== 
 

Program aborted. Backtrace:
#0  0x4E4B417
#1  0x4E4CB12
#2  0x4F1D208
#3  0x400E87 in MAIN__ at r.f90:17 (discriminator 1)
==27652== 
==27652== HEAP SUMMARY:
==27652==     in use at exit: 3,700 bytes in 18 blocks
==27652==   total heap usage: 25 allocs, 7 frees, 11,845 bytes allocated
==27652== 
==27652== LEAK SUMMARY:
==27652==    definitely lost: 0 bytes in 0 blocks
==27652==    indirectly lost: 0 bytes in 0 blocks
==27652==      possibly lost: 0 bytes in 0 blocks
==27652==    still reachable: 3,700 bytes in 18 blocks
==27652==         suppressed: 0 bytes in 0 blocks
==27652== Rerun with --leak-check=full to see details of leaked memory
==27652== 
==27652== For counts of detected and suppressed errors, rerun with: -v
==27652== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 2 from 2)
Abgebrochen
Comment 6 Dominique d'Humieres 2014-03-16 00:34:42 UTC
> This is not PR 47674 (or so I think).

Why do you think so? The valgrind report in comment 5 is the same as the one in pr47674 comment 0.

Tobias Burnus wrote:

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

Are you using MALLOC_CHECK_?
Comment 7 Thomas Koenig 2014-03-16 10:09:28 UTC
OK, looks like it is the same bug after all.
After I removed MALLOC_CHECK_ and
MALLOC_PERTURB_, things "worked".   I thought it
was a different bug because I got an abort, not
a segfault.

Marking as duplicate.

*** This bug has been marked as a duplicate of bug 47674 ***