This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[Patch, fortran] PR24813 - ICE with scalarization LEN of character types
- From: Paul dot Thomas at jet dot uk (Paul Thomas)
- To: fortran at gcc dot gnu dot org, gcc-patches at gnu dot org
- Date: Fri, 28 Apr 2006 08:59:20 +0100
- Subject: [Patch, fortran] PR24813 - ICE with scalarization LEN of character types
:ADDPATCH fortran:
This patch fixes PR24813 in which an ICE in trans-expr.c
(gfc_conv_array_constructor_expr) would follow the attempted use of an
array constructor as an argument for the intrinsic function LEN. This
arose for the lack of any of the parathenalia of the scalarizer; in
particular a gfc_ss. Rather than go to the trouble of building a loop
in order to obtain a string length, we instead use one of the array
constructor helper functions to obtain it directly.
Regtested on Cygwin_NT/Athlon_M
OK for trunk and 4.1?
Paul
2006-04-23 Paul Thomas <pault@gcc.gnu.org>
PR fortran/24813
* trans-array.c (get_array_ctor_strlen): Remove static attribute.
* trans.h: Add prototype for get_array_ctor_strlen.
* trans-intrinsic.c (gfc_conv_intrinsic_len): Switch on EXPR_ARRAY
and call get_array_ctor_strlen.
2006-04-23 Paul Thomas <pault@gcc.gnu.org>
PR fortran/24813
* gfortran.dg/char_cons_len_1.f90: New test.
Index: gcc/fortran/trans-array.c
===================================================================
--- gcc/fortran/trans-array.c (révision 113192)
+++ gcc/fortran/trans-array.c (copie de travail)
@@ -1328,7 +1328,7 @@
/* Figure out the string length of a character array constructor.
Returns TRUE if all elements are character constants. */
-static bool
+bool
get_array_ctor_strlen (gfc_constructor * c, tree * len)
{
bool is_const;
Index: gcc/fortran/trans.h
===================================================================
--- gcc/fortran/trans.h (révision 113192)
+++ gcc/fortran/trans.h (copie de travail)
@@ -419,6 +419,9 @@
extern GTY(()) tree gfc_static_ctors;
void gfc_generate_constructors (void);
+/* Get the string length of an array constructor. */
+bool get_array_ctor_strlen (gfc_constructor *, tree *);
+
/* Generate a runtime error check. */
void gfc_trans_runtime_check (tree, tree, stmtblock_t *);
Index: gcc/fortran/trans-intrinsic.c
===================================================================
--- gcc/fortran/trans-intrinsic.c (révision 113192)
+++ gcc/fortran/trans-intrinsic.c (copie de travail)
@@ -2258,6 +2258,13 @@
len = build_int_cst (NULL_TREE, arg->value.character.length);
break;
+ case EXPR_ARRAY:
+ /* Obtain the string length from the function used by
+ trans-array.c(gfc_trans_array_constructor). */
+ len = NULL_TREE;
+ get_array_ctor_strlen (arg->value.constructor, &len);
+ break;
+
default:
if (arg->expr_type == EXPR_VARIABLE
&& (arg->ref == NULL || (arg->ref->next == NULL
! { dg-do compile }
! Tests the fix for PR24813 in which a character array
! constructor, as an argument for LEN, would cause an ICE.
!
character(11) :: chr1, chr2
i = len ((/chr1, chr2, "ggg"/))
j = len ((/"abcdefghijk", chr1, chr2/))
k = len ((/'hello ','goodbye'/))
l = foo ("yes siree, Bob")
if (any ((/11,11,7,14/) /= (/i,j,k,l/))) call abort ()
contains
integer function foo (arg)
character(*) :: arg
character(len(arg)) :: ctor
foo = len ((/ctor/))
end function foo
end