https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85547
Bug ID: 85547 Summary: Run-time error: character array constructor Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: w6ws at earthlink dot net Target Milestone: --- The following compiles with gfortran (v4.8.4, 5.4, and a snapshot of todays 9.0), but abends at run-time. Note there are actually two problems shown here: First, the passed in string size is bad. It should be '16', not the length of the first element. Second, the deallocations after the call fail - which cause the abend. This test case runs fine with NAG and PGI. (I've not tried Intel yet, but I can if needed.) wws@w6ws-4:/tmp$ cat testch.f90 program testch implicit none character(10) :: path path = 'xyz/' call print_strings ((/ character(16) :: & trim(path) // "one", & trim(path) // "three", & trim(path) // "five", & trim(path) // "eight", & trim(path) // "forty two" /) ) contains subroutine print_strings (s) character(*), intent(in) :: s(:) integer :: i do, i=1, size(s) print *, i, '>', s(i), '<' end do end subroutine end program wws@w6ws-4:/tmp$ /usr/local/gcc-trunk/bin/gfortran --version GNU Fortran (GCC) 9.0.0 20180426 (experimental) Copyright (C) 2018 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. wws@w6ws-4:/tmp$ /usr/local/gcc-trunk/bin/gfortran -g testch.f90 Running under gdb: wws@w6ws-4:/tmp$ gdb a.out GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1 Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from a.out...done. (gdb) run Starting program: /tmp/a.out 1 >xyz/one< 2 >xyz/thr< 3 >xyz/fiv< 4 >xyz/eig< 5 >xyz/for< *** Error in `/tmp/a.out': free(): invalid next size (fast): 0x0000000000605640 *** ======= Backtrace: ========= /lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7ffff6eb87e5] /lib/x86_64-linux-gnu/libc.so.6(+0x8037a)[0x7ffff6ec137a] /lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7ffff6ec553c] /tmp/a.out[0x4012d9] /tmp/a.out[0x40131e] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7ffff6e61830] /tmp/a.out[0x4008b9] ======= Memory map: ======== 00400000-00402000 r-xp 00000000 08:0a 40632824 /tmp/a.out 00601000-00602000 rw-p 00001000 08:0a 40632824 /tmp/a.out 00602000-00623000 rw-p 00000000 00:00 0 [heap] 7ffff0000000-7ffff0021000 rw-p 00000000 00:00 0 7ffff0021000-7ffff4000000 ---p 00000000 00:00 0 7ffff6e41000-7ffff7001000 r-xp 00000000 08:0a 20190243 /lib/x86_64-linux-gnu/libc-2.23.so 7ffff7001000-7ffff7201000 ---p 001c0000 08:0a 20190243 /lib/x86_64-linux-gnu/libc-2.23.so 7ffff7201000-7ffff7205000 r--p 001c0000 08:0a 20190243 /lib/x86_64-linux-gnu/libc-2.23.so 7ffff7205000-7ffff7207000 rw-p 001c4000 08:0a 20190243 /lib/x86_64-linux-gnu/libc-2.23.so 7ffff7207000-7ffff720b000 rw-p 00000000 00:00 0 7ffff720b000-7ffff724a000 r-xp 00000000 08:0a 48497154 /usr/local/gcc-trunk/lib64/libquadmath.so.0.0.0 7ffff724a000-7ffff7449000 ---p 0003f000 08:0a 48497154 /usr/local/gcc-trunk/lib64/libquadmath.so.0.0.0 7ffff7449000-7ffff744a000 rw-p 0003e000 08:0a 48497154 /usr/local/gcc-trunk/lib64/libquadmath.so.0.0.0 7ffff744a000-7ffff7461000 r-xp 00000000 08:0a 48497146 /usr/local/gcc-trunk/lib64/libgcc_s.so.1 7ffff7461000-7ffff7660000 ---p 00017000 08:0a 48497146 /usr/local/gcc-trunk/lib64/libgcc_s.so.1 7ffff7660000-7ffff7661000 rw-p 00016000 08:0a 48497146 /usr/local/gcc-trunk/lib64/libgcc_s.so.1 7ffff7661000-7ffff7769000 r-xp 00000000 08:0a 20185261 /lib/x86_64-linux-gnu/libm-2.23.so 7ffff7769000-7ffff7968000 ---p 00108000 08:0a 20185261 /lib/x86_64-linux-gnu/libm-2.23.so 7ffff7968000-7ffff7969000 r--p 00107000 08:0a 20185261 /lib/x86_64-linux-gnu/libm-2.23.so 7ffff7969000-7ffff796a000 rw-p 00108000 08:0a 20185261 /lib/x86_64-linux-gnu/libm-2.23.so 7ffff796a000-7ffff7bd4000 r-xp 00000000 08:0a 48497159 /usr/local/gcc-trunk/lib64/libgfortran.so.5.0.0 7ffff7bd4000-7ffff7dd4000 ---p 0026a000 08:0a 48497159 /usr/local/gcc-trunk/lib64/libgfortran.so.5.0.0 7ffff7dd4000-7ffff7dd6000 rw-p 0026a000 08:0a 48497159 /usr/local/gcc-trunk/lib64/libgfortran.so.5.0.0 7ffff7dd6000-7ffff7dd7000 rw-p 00000000 00:00 0 7ffff7dd7000-7ffff7dfd000 r-xp 00000000 08:0a 20190239 /lib/x86_64-linux-gnu/ld-2.23.so 7ffff7fd0000-7ffff7fd4000 rw-p 00000000 00:00 0 7ffff7ff5000-7ffff7ff7000 rw-p 00000000 00:00 0 7ffff7ff7000-7ffff7ffa000 r--p 00000000 00:00 0 [vvar] 7ffff7ffa000-7ffff7ffc000 r-xp 00000000 00:00 0 [vdso] 7ffff7ffc000-7ffff7ffd000 r--p 00025000 08:0a 20190239 /lib/x86_64-linux-gnu/ld-2.23.so 7ffff7ffd000-7ffff7ffe000 rw-p 00026000 08:0a 20190239 /lib/x86_64-linux-gnu/ld-2.23.so 7ffff7ffe000-7ffff7fff000 rw-p 00000000 00:00 0 7ffffffde000-7ffffffff000 rw-p 00000000 00:00 0 [stack] ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall] Program received signal SIGABRT, Aborted. 0x00007ffff6e76428 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54 54 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory. (gdb) where #0 0x00007ffff6e76428 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54 #1 0x00007ffff6e7802a in __GI_abort () at abort.c:89 #2 0x00007ffff6eb87ea in __libc_message (do_abort=do_abort@entry=2, fmt=fmt@entry=0x7ffff6fd1ed8 "*** Error in `%s': %s: 0x%s ***\n") at ../sysdeps/posix/libc_fatal.c:175 #3 0x00007ffff6ec137a in malloc_printerr (ar_ptr=<optimized out>, ptr=<optimized out>, str=0x7ffff6fd1f50 "free(): invalid next size (fast)", action=3) at malloc.c:5006 #4 _int_free (av=<optimized out>, p=<optimized out>, have_lock=0) at malloc.c:3867 #5 0x00007ffff6ec553c in __GI___libc_free (mem=<optimized out>) at malloc.c:2968 #6 0x00000000004012d9 in testch () at testch.f90:11 #7 0x000000000040131e in main (argc=1, argv=0x7fffffffe275) at testch.f90:11 #8 0x00007ffff6e61830 in __libc_start_main (main=0x4012ea <main>, argc=1, argv=0x7fffffffdef8, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffdee8) at ../csu/libc-start.c:291 #9 0x00000000004008b9 in _start () (gdb) quit A debugging session is active. Inferior 1 [process 24998] will be killed. Quit anyway? (y or n) y wws@w6ws-4:/tmp$