Hi, here's an annoying one. Default initializing a character array in a derived type leads to zero padded strings instead of space-padded ones. E.g. ! This works correctly: character(len=16) :: tdefi(2) = (/'0z1jan0000','1hr '/) ! 1234567890 ! Broken in derived type: type t_ctl character(len=16) :: tdefi(2) = (/'0z1jan0000','1hr '/) ! 1234567890 end type t_ctl See the attached program for details.
Created attachment 13332 [details] Demo code
I'll have a look.
The strings aren't actually padded. From the assembly output: _ctl.1000: .ascii "0z1jan0000" .space 6 .ascii "1hr " .space 6 .align 5 _tdefi.996: .ascii "0z1jan0000 " .ascii "1hr " .const In other words, they are put into the right memory locations, but without any regard to their string nature. I've not yet figured out where this goes wrong.
Created attachment 14708 [details] Fix for PR - not yet regtested
I have applied the patch in #4 and I have a lot of failures: [ibook-dhum] f90/bug% cat pr30200_red.f90 type test character(len=100) :: names(5) end type test type(test) :: keyword keyword%names=(/"a","b","c","d","e"/) END [ibook-dhum] f90/bug% gfc pr30200_red.f90 f951: internal compiler error: Bus error Please submit a full bug report, with preprocessed source if appropriate. See <http://gcc.gnu.org/bugs.html> for instructions. I did not looked yet at all the failures, but all the one I have looked at gives a bus error.
(In reply to comment #5) > I did not looked yet at all the failures, but all the one I have looked at > gives a bus error. Thanks Dominique. I'm looking at PR32129 first and then this. I am sure that this fix is fundamentally right but that I have just forgotten a check on the existence of something. Cheers Paul
(In reply to comment #5) > I did not looked yet at all the failures, but all the one I have looked at > gives a bus error. In fact, I do not check that the initializer is not NULL. Paul
Now works as advertized without regression on i686-apple-darwin9.
Subject: Bug 31487 Author: pault Date: Sun Dec 9 09:17:24 2007 New Revision: 130719 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130719 Log: 2007-12-09 Paul Thomas <pault@gcc.gnu.org> PR fortran/32129 * dump-parse-tree.c (gfc_show_expr_n): New function for debugging. * gfortran.h : Add prototype for gfc_show_expr_n. * expr.c (simplify_constructor): Copy the constructor expression and try to simplify that. If success, replace the original. Otherwise discard the copy, keep going through the structure and return success. PR fortran/31487 * decl.c (build_struct): Pad out default initializers with spaces to the component character length. 2007-12-09 Paul Thomas <pault@gcc.gnu.org> PR fortran/32129 * gfortran.dg/derived_comp_array_ref_6.f90: New test. * gfortran.dg/derived_comp_array_ref_7.f90: New test. PR fortran/31487 * gfortran.dg/char_component_initializer_1.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/char_component_initializer_1.f90 trunk/gcc/testsuite/gfortran.dg/derived_comp_array_ref_6.f90 trunk/gcc/testsuite/gfortran.dg/derived_comp_array_ref_7.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/decl.c trunk/gcc/fortran/dump-parse-tree.c trunk/gcc/fortran/expr.c trunk/gcc/fortran/gfortran.h trunk/gcc/testsuite/ChangeLog
Fixed on trunk Paul