This one is strange; it is with recent trunk. ig25@linux-fd1f:~/Krempel/Char-4> cat foo.f90 program main implicit none character(len=3) :: c(3) c = 'x' print '(3(A,"|"))', (/ (/ trim(c(1)), 'a' /)//'c', 'cd' /) print '(3(A,"|"))', (/ (/ c(1)(1:len_trim(c(1))), 'a' /)//'c', 'cd' /) print '(3(A,"|"))', (/ (/ c(1)(1:1), 'a' /)//'c', 'cd' /) end program main ig25@linux-fd1f:~/Krempel/Char-4> gfortran foo.f90 ig25@linux-fd1f:~/Krempel/Char-4> ./a.out xc|ac|cd| x |a |cd| xc|ac|cd| The second line should be identical to the first and third one. Modified from nested_array_constructor_2.f90, BTW. Goes back at least to 4.4.1, so probably not a regression.
gfortran 4.2.5 tries to grab 4 GB of memory and eventually I killed the job. With 4.3.something, I get troutmask:sgk[211] gfc43 -o z df.f90 df.f90: In function 'main': df.f90:5: internal compiler error: Segmentation fault: 11 Please submit a full bug report, with preprocessed source if appropriate. Definitely, an interesting bug.
Of course, I can't replace trim(c(1)) with c(1)(1:len_trim(c(1)) until this is resolved (which is why I found the bug in the first place), so mark this as blocking PR 47065.
Reduced test case: program main implicit none character(len=*), parameter :: fmt='(2(A,"|"))' integer :: i character(len=4) :: q q = 'yy' i = 2 print fmt, (/ trim(q), 'ae' /)//'c' print fmt, (/ q(1:i), 'ae' /)//'c' end program main This prints yyc|aec| yy c|ae c| so the string length of the array constructor is wrong.
More reduced test case: program main implicit none character(len=*), parameter :: fmt='(A,A)' integer :: i character(len=4) :: q q = 'abcd' i = 2 print fmt, (/q(1:i) /),"|" end program main produces ab | May be related to PR 44735, which is also an issue with substrings with non-constant length. Paul, this is a case of something (trans-*?) picking up the wrong string length and ignoring the substring. Do you have any idea where to start looking?
Dear Thomas, > Paul, this is a case of something (trans-*?) picking up the > wrong string length and ignoring the substring. Do you have > any idea where to start looking? > Almost certainly. I am very busy right now with reallocation in scalar assignments. I'll flag this one up. cheers Paul
Author: pault Date: Sat Feb 19 15:03:27 2011 New Revision: 170317 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=170317 Log: 2011-02-19 Paul Thomas <pault@gcc.gnu.org> PR fortran/47348 * trans-array.c (get_array_ctor_all_strlen): Move up in file. (get_array_ctor_var_strlen): Add block dummy and add call to get_array_ctor_all_strlen instead of giving up on substrings. Call gcc_unreachable for default case. (get_array_ctor_strlen): Add extra argument to in call to get_array_ctor_var_strlen. 2011-02-19 Paul Thomas <pault@gcc.gnu.org> PR fortran/47348 * gfortran.dg/array_constructor_36.f90 : New test. * gfortran.dg/bounds_check_10.f90 : Change dg-output message to allow for comparison between different elements of the array constructor at different levels of optimization. Added: trunk/gcc/testsuite/gfortran.dg/array_constructor_36.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/trans-array.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gfortran.dg/bounds_check_10.f90
Any plan to backport the fix in revision 170317?
(In reply to comment #7) > Any plan to backport the fix in revision 170317? I had not planned so to do but would respond positively to popular pressure how far back would you want to go? Paul
Hi Paul, > (In reply to comment #7) >> Any plan to backport the fix in revision 170317? > > I had not planned so to do but would respond positively to popular pressure how > far back would you want to go? I think 4.5 would be great. Anything further back is probably unneeded (the bug has remained undetected for a few years now...) Thomas
Author: pault Date: Sun Mar 13 17:37:43 2011 New Revision: 170923 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=170923 Log: 2011-03-13 Paul Thomas <pault@gcc.gnu.org> PR fortran/47348 * trans-array.c (get_array_ctor_all_strlen): Move up in file. (get_array_ctor_var_strlen): Add block dummy and add call to get_array_ctor_all_strlen instead of giving up on substrings. Call gcc_unreachable for default case. (get_array_ctor_strlen): Add extra argument to in call to get_array_ctor_var_strlen. 2011-03-13 Paul Thomas <pault@gcc.gnu.org> PR fortran/47348 * gfortran.dg/array_constructor_36.f90 : New test. * gfortran.dg/bounds_check_10.f90 : Change dg-output message to allow for comparison between different elements of the array constructor at different levels of optimization. Added: branches/gcc-4_5-branch/gcc/testsuite/gfortran.dg/array_constructor_36.f90 Modified: branches/gcc-4_5-branch/gcc/fortran/ChangeLog branches/gcc-4_5-branch/gcc/fortran/trans-array.c branches/gcc-4_5-branch/gcc/testsuite/ChangeLog
(In reply to comment #10) Fixed on 4.5 and trunk. Closing Thanks for the report. Paul