[Bug fortran/85547] Run-time error: character array constructor

2023-09-06 Thread anlauf at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85547

anlauf at gcc dot gnu.org changed:

   What|Removed |Added

 CC||mailling-lists-bd at posteo 
dot de

--- Comment #7 from anlauf at gcc dot gnu.org ---
*** Bug 111304 has been marked as a duplicate of this bug. ***

[Bug fortran/85547] Run-time error: character array constructor

2021-01-20 Thread anlauf at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85547

anlauf at gcc dot gnu.org changed:

   What|Removed |Added

 CC||anlauf at gcc dot gnu.org

--- Comment #6 from anlauf at gcc dot gnu.org ---
The trim() and string concatenation are not even needed to see the string
length getting lost.

Example:

program p
  implicit none
  character(10) :: path = 'xyz/'
  print *, len  ( [ character(16) :: path ] ) ! ok
  call print_string ( [ character(16) :: path ] ) ! typespec lost
contains
  subroutine print_string (s)
character(*), intent(in) :: s(:)
print *, len(s), len(s)==16
  end subroutine
end program

prints:

  16
  10 F

Inspection of the tree-dump shows that the temporary creation for the
subroutine call looks like we initially have the proper string length
after the array constructor

atmp.6.dtype = {.elem_len=16, .rank=1, .type=6};
atmp.6.dim[0].stride = 1;
atmp.6.dim[0].lbound = 0;
atmp.6.dim[0].ubound = 0;
atmp.6.span = 16;

which gets copied to the temporary

atmp.9.dtype = {.elem_len=10, .rank=1, .type=6};
atmp.9.dim[0].stride = 1;
atmp.9.dim[0].lbound = 0;
atmp.9.dim[0].ubound = 0;
atmp.9.span = 10;

I wonder where we get this from.

Besides, we actually create two temporaries in succession instead of just
one...

[Bug fortran/85547] Run-time error: character array constructor

2018-04-30 Thread w6ws at earthlink dot net
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85547

--- Comment #5 from Walter Spector  ---
Turns out my third case, in comment #2, is incorrect.  To correct it, line 5
should read:

  path = (/ 'xyz/' /)

With this correction, my current trunk snapshot works ok.  (Doesn't apply to
the first two examples though.)

[Bug fortran/85547] Run-time error: character array constructor

2018-04-27 Thread dominiq at lps dot ens.fr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85547

Dominique d'Humieres  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2018-04-27
 Ever confirmed|0   |1

--- Comment #4 from Dominique d'Humieres  ---
Confirmed.

[Bug fortran/85547] Run-time error: character array constructor

2018-04-26 Thread kargl at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85547

kargl at gcc dot gnu.org changed:

   What|Removed |Added

   Priority|P3  |P4
 CC||kargl at gcc dot gnu.org

--- Comment #3 from kargl at gcc dot gnu.org ---
workaround.  Create a temporary.

  character(len=:), allocatable :: s(:)
  path = 'xyz/'
  s = (/ character(16) :: &
  trim(path) // "one",  &
  trim(path) // "three",  &
  trim(path) // "five",  &
  trim(path) // "eight",  &
  trim(path) // "forty two" /)
  call print_strings (s)

[Bug fortran/85547] Run-time error: character array constructor

2018-04-26 Thread w6ws at earthlink dot net
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85547

--- Comment #2 from Walter Spector  ---
Third variant.  This one messes up NAG and PGI too:

wws@w6ws-4:/tmp$ cat testch3.f90
program testch
  implicit none

  character(:), allocatable :: path(:)
  path = 'xyz/'
  path = (/ character(16) :: &
  path // "one",  &
  path // "three",  &
  path // "five",  &
  path // "eight",  &
  path // "forty two" /)
  call print_strings (path)

contains

  subroutine print_strings (s)
character(*), intent(in) :: s(:)

integer :: i

print *, 'character string length:', len (s)
print *, 'array size =', size (s)

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 -g testch3.f90
wws@w6ws-4:/tmp$ a.out

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0  0x7fe073c854af in ???
#1  0x400ea3 in testch
at /tmp/testch3.f90:5
#2  0x401b66 in main
at /tmp/testch3.f90:12
Segmentation fault (core dumped)
wws@w6ws-4:/tmp$

[Bug fortran/85547] Run-time error: character array constructor

2018-04-26 Thread w6ws at earthlink dot net
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85547

--- Comment #1 from Walter Spector  ---
Slightly different test case - using allocatable string length instead of the
trims.  However the same problems are evident:

program testch
  implicit none

  character(:), allocatable :: path
  path = 'xyz/'
  call print_strings ((/ character(16) :: &
  path // "one",  &
  path // "three",  &
  path // "five",  &
  path // "eight",  &
  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 -g testch.f90
wws@w6ws-4:/tmp$ a.out
   1 >xyz/one<
   2 >xyz/thr<
   3 >xyz/fiv<
   4 >xyz/eig<
   5 >xyz/for<
*** Error in `a.out': free(): invalid next size (fast): 0x0217b640 ***
=== Backtrace: =
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7fac7b49c7e5]
/lib/x86_64-linux-gnu/libc.so.6(+0x8037a)[0x7fac7b4a537a]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7fac7b4a953c]
a.out[0x401280]
a.out[0x4012c5]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7fac7b445830]
a.out[0x400949]
=== Memory map: 
0040-00402000 r-xp  08:0a 40632824  
/tmp/a.out
00601000-00602000 rw-p 1000 08:0a 40632824  
/tmp/a.out
02178000-02199000 rw-p  00:00 0  [heap]
7fac7400-7fac74021000 rw-p  00:00 0 
7fac74021000-7fac7800 ---p  00:00 0 
7fac7b425000-7fac7b5e5000 r-xp  08:0a 20190243  
/lib/x86_64-linux-gnu/libc-2.23.so
7fac7b5e5000-7fac7b7e5000 ---p 001c 08:0a 20190243  
/lib/x86_64-linux-gnu/libc-2.23.so
7fac7b7e5000-7fac7b7e9000 r--p 001c 08:0a 20190243  
/lib/x86_64-linux-gnu/libc-2.23.so
7fac7b7e9000-7fac7b7eb000 rw-p 001c4000 08:0a 20190243  
/lib/x86_64-linux-gnu/libc-2.23.so
7fac7b7eb000-7fac7b7ef000 rw-p  00:00 0 
7fac7b7ef000-7fac7b82e000 r-xp  08:0a 48497154  
/usr/local/gcc-trunk/lib64/libquadmath.so.0.0.0
7fac7b82e000-7fac7ba2d000 ---p 0003f000 08:0a 48497154  
/usr/local/gcc-trunk/lib64/libquadmath.so.0.0.0
7fac7ba2d000-7fac7ba2e000 rw-p 0003e000 08:0a 48497154  
/usr/local/gcc-trunk/lib64/libquadmath.so.0.0.0
7fac7ba2e000-7fac7ba45000 r-xp  08:0a 48497146  
/usr/local/gcc-trunk/lib64/libgcc_s.so.1
7fac7ba45000-7fac7bc44000 ---p 00017000 08:0a 48497146  
/usr/local/gcc-trunk/lib64/libgcc_s.so.1
7fac7bc44000-7fac7bc45000 rw-p 00016000 08:0a 48497146  
/usr/local/gcc-trunk/lib64/libgcc_s.so.1
7fac7bc45000-7fac7bd4d000 r-xp  08:0a 20185261  
/lib/x86_64-linux-gnu/libm-2.23.so
7fac7bd4d000-7fac7bf4c000 ---p 00108000 08:0a 20185261  
/lib/x86_64-linux-gnu/libm-2.23.so
7fac7bf4c000-7fac7bf4d000 r--p 00107000 08:0a 20185261  
/lib/x86_64-linux-gnu/libm-2.23.so
7fac7bf4d000-7fac7bf4e000 rw-p 00108000 08:0a 20185261  
/lib/x86_64-linux-gnu/libm-2.23.so
7fac7bf4e000-7fac7c1b8000 r-xp  08:0a 48497159  
/usr/local/gcc-trunk/lib64/libgfortran.so.5.0.0
7fac7c1b8000-7fac7c3b8000 ---p 0026a000 08:0a 48497159  
/usr/local/gcc-trunk/lib64/libgfortran.so.5.0.0
7fac7c3b8000-7fac7c3ba000 rw-p 0026a000 08:0a 48497159  
/usr/local/gcc-trunk/lib64/libgfortran.so.5.0.0
7fac7c3ba000-7fac7c3bb000 rw-p  00:00 0 
7fac7c3bb000-7fac7c3e1000 r-xp  08:0a 20190239  
/lib/x86_64-linux-gnu/ld-2.23.so
7fac7c5b9000-7fac7c5bd000 rw-p  00:00 0 
7fac7c5de000-7fac7c5e rw-p  00:00 0 
7fac7c5e-7fac7c5e1000 r--p 00025000 08:0a 20190239  
/lib/x86_64-linux-gnu/ld-2.23.so
7fac7c5e1000-7fac7c5e2000 rw-p 00026000 08:0a 20190239  
/lib/x86_64-linux-gnu/ld-2.23.so
7fac7c5e2000-7fac7c5e3000 rw-p  00:00 0 
7ffd9dc1f000-7ffd9dc4 rw-p  00:00 0 
[stack]
7ffd9dd24000-7ffd9dd27000 r--p  00:00 0  [vvar]
7ffd9dd27000-7ffd9dd29000 r-xp  00:00 0  [vdso]
ff60-ff601000 r-xp  00:00 0 
[vsyscall]

Program received signal SIGABRT: Process abort signal.

Backtrace for this error:
#0  0x7fac7b45a4af in ???
#1  0x7fac7b45a428 in ???
#2  0x7fac7b45c029 in ???
#3  0x7fac7b49c7e9 in ???
#4  0x7fac7b4a5379 in ???
#5  0x7fac7b4a953b in ???
#6  0x40127f in testch
at /tmp/testch.f90:11
#7  0x4012c4 in main
at /tmp/testch.f90:11
Aborted (core dumped)
wws@w6ws-4:/tmp$