The following program gives an ICE. One reason could be the global variables. (cf. PR27997 comment 21). implicit none integer i character(len=2) :: c(3) c = 'a' c = [ [ trim(c(1)), 'a' ]//'c', 'cd' ] print *, c end Variants to check (or combinations of those): - Compile with -fbounds-check - Use c = '' or c = 'ab' - Use typespec after PR27997 has been fixed, either on the inner or on the outer loop. E.g. c = [ [ character(1):: trim(c(1)), 'a' ]//'c', 'cd' ] etc.
Created attachment 15474 [details] Backtrace Confirmed. Backtrace is attached.
Created attachment 15655 [details] Hackish patch It seems the problem lies in gfc_conv_string_length, that can be called with a gfc_charlen whose length is NULL. This patch is somewhat a prove of concept of this, just creating a dummy length if it is NULL there; this prevents the ICEs described above. Of course this is surely not the correct place to do this initialization, I'll try to find it out later and work out a real patch.
Created attachment 15663 [details] Testcase without nested array constructors Actually, this does not depend on nested array constructors as this test-case proves (and also has nothing to do with the globals used for bounds-checking, it seems). I believe the problem is that the gfc_expr* corresponding to the concatenation doesn't have a cl->length set on its ts (because the arguments don't have one when resolution is called); this NULL later causes the ICE. When this expression turns up in an assignment, this does not matter as the expected length is known from the target's character length definition. But when there is no "expected" charlen (like in the nested constructor or in a function call as in this test) it is needed and the NULL pointer dereferenced. Hopefully I can soon come up with a real solution to this patch.
Created attachment 15664 [details] Testcase without nested array constructors Actually, this does not depend on nested array constructors as this test-case proves (and also has nothing to do with the globals used for bounds-checking, it seems). I believe the problem is that the gfc_expr* corresponding to the concatenation doesn't have a cl->length set on its ts (because the arguments don't have one when resolution is called); this NULL later causes the ICE. When this expression turns up in an assignment, this does not matter as the expected length is known from the target's character length definition. But when there is no "expected" charlen (like in the nested constructor or in a function call as in this test) it is needed and the NULL pointer dereferenced. Hopefully I can soon come up with a real solution to this problem.
After coming back to this bug, I believe the problem is that gfc_conv_expr takes care of finding out string lengths' for things like TRIM(x) which don't have a cl->length, but gfc_conv_expr_descriptor which is called e.g. for the array constructors does not do so and calls gfc_conv_string_length with a cl whose length is NULL. As the problem seems to be specific to array constructors and all array constructor elements must have the same character length, I propose to re-use gfc_conv_expr in gfc_conv_string_length to find out the string length if it is NULL by taking the first element of each array constructor and then calling gfc_conv_expr to get the result's string_length. I'll submit a patch shortly if no further problems occur.
Subject: Bug 35846 Author: domob Date: Sun Sep 21 15:33:37 2008 New Revision: 140529 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=140529 Log: 2008-09-21 Daniel Kraft <d@domob.eu> PR fortran/35846 * trans.h (gfc_conv_string_length): New argument `expr'. * trans-expr.c (flatten_array_ctors_without_strlen): New method. (gfc_conv_string_length): New argument `expr' that is used in a new special case handling if cl->length is NULL. (gfc_conv_subref_array_arg): Pass expr to gfc_conv_string_length. * trans-array.c (gfc_conv_expr_descriptor): Ditto. (gfc_trans_auto_array_allocation): Pass NULL as new expr. (gfc_trans_g77_array), (gfc_trans_dummy_array_bias): Ditto. (gfc_trans_deferred_array): Ditto. (gfc_trans_array_constructor): Save and restore old values of globals used for bounds checking. * trans-decl.c (gfc_trans_dummy_character): Ditto. (gfc_trans_auto_character_variable): Ditto. 2008-09-21 Daniel Kraft <d@domob.eu> PR fortran/35846 * gfortran.dg/nested_array_constructor_1.f90: New test. * gfortran.dg/nested_array_constructor_2.f90: New test. * gfortran.dg/nested_array_constructor_3.f90: New test. * gfortran.dg/nested_array_constructor_4.f90: New test. * gfortran.dg/nested_array_constructor_5.f90: New test. * gfortran.dg/nested_array_constructor_6.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/nested_array_constructor_1.f90 trunk/gcc/testsuite/gfortran.dg/nested_array_constructor_2.f90 trunk/gcc/testsuite/gfortran.dg/nested_array_constructor_3.f90 trunk/gcc/testsuite/gfortran.dg/nested_array_constructor_4.f90 trunk/gcc/testsuite/gfortran.dg/nested_array_constructor_5.f90 trunk/gcc/testsuite/gfortran.dg/nested_array_constructor_6.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/trans-array.c trunk/gcc/fortran/trans-decl.c trunk/gcc/fortran/trans-expr.c trunk/gcc/fortran/trans.h trunk/gcc/testsuite/ChangeLog
Fixed on trunk.