+2007-05-26 Paul Thomas <pault@gcc.gnu.org>
+
+ PR fortran/31219
+ * trans.h : Add no_function_call bitfield to gfc_se structure.
+ Add stmtblock_t argument to prototype of get_array_ctor_strlen.
+ * trans-array.c (get_array_ctor_all_strlen): New function.
+ (get_array_ctor_strlen): Add new stmtblock_t argument and call
+ new function for character elements that are not constants,
+ arrays or variables.
+ (gfc_conv_array_parameter): Call get_array_ctor_strlen to get
+ good string length.
+ * trans-intrinsic (gfc_conv_intrinsic_len): Add new argument
+ to call of get_array_ctor_strlen.
+
2007-05-25 Kazu Hirata <kazu@codesourcery.com>
* intrinsic.texi: Fix typos.
}
+/* A catch-all to obtain the string length for anything that is not a
+ constant, array or variable. */
+static void
+get_array_ctor_all_strlen (stmtblock_t *block, gfc_expr *e, tree *len)
+{
+ gfc_se se;
+ gfc_ss *ss;
+
+ /* Don't bother if we already know the length is a constant. */
+ if (*len && INTEGER_CST_P (*len))
+ return;
+
+ if (!e->ref && e->ts.cl->length
+ && e->ts.cl->length->expr_type == EXPR_CONSTANT)
+ {
+ /* This is easy. */
+ gfc_conv_const_charlen (e->ts.cl);
+ *len = e->ts.cl->backend_decl;
+ }
+ else
+ {
+ /* Otherwise, be brutal even if inefficient. */
+ ss = gfc_walk_expr (e);
+ gfc_init_se (&se, NULL);
+
+ /* No function call, in case of side effects. */
+ se.no_function_call = 1;
+ if (ss == gfc_ss_terminator)
+ gfc_conv_expr (&se, e);
+ else
+ gfc_conv_expr_descriptor (&se, e, ss);
+
+ /* Fix the value. */
+ *len = gfc_evaluate_now (se.string_length, &se.pre);
+
+ gfc_add_block_to_block (block, &se.pre);
+ gfc_add_block_to_block (block, &se.post);
+
+ e->ts.cl->backend_decl = *len;
+ }
+}
+
+
/* Figure out the string length of a character array constructor.
Returns TRUE if all elements are character constants. */
bool
-get_array_ctor_strlen (gfc_constructor * c, tree * len)
+get_array_ctor_strlen (stmtblock_t *block, gfc_constructor * c, tree * len)
{
bool is_const;
break;
case EXPR_ARRAY:
- if (!get_array_ctor_strlen (c->expr->value.constructor, len))
+ if (!get_array_ctor_strlen (block, c->expr->value.constructor, len))
is_const = false;
break;
default:
is_const = false;
-
- /* Hope that whatever we have possesses a constant character
- length! */
- if (!(*len && INTEGER_CST_P (*len)) && c->expr->ts.cl)
- {
- gfc_conv_const_charlen (c->expr->ts.cl);
- *len = c->expr->ts.cl->backend_decl;
- }
- /* TODO: For now we just ignore anything we don't know how to
- handle, and hope we can figure it out a different way. */
+ get_array_ctor_all_strlen (block, c->expr, len);
break;
}
}
c = ss->expr->value.constructor;
if (ss->expr->ts.type == BT_CHARACTER)
{
- bool const_string = get_array_ctor_strlen (c, &ss->string_length);
+ bool const_string = get_array_ctor_strlen (&loop->pre, c, &ss->string_length);
if (!ss->string_length)
gfc_todo_error ("complex character array constructors");
+ ss->expr->ts.cl->backend_decl = ss->string_length;
+
+
type = gfc_get_character_type_len (ss->expr->ts.kind, ss->string_length);
if (const_string)
type = build_pointer_type (type);
&& expr->ref->u.ar.type == AR_FULL);
sym = full_array_var ? expr->symtree->n.sym : NULL;
+ if (expr->expr_type == EXPR_ARRAY && expr->ts.type == BT_CHARACTER)
+ {
+ get_array_ctor_strlen (&se->pre, expr->value.constructor, &tmp);
+ expr->ts.cl->backend_decl = gfc_evaluate_now (tmp, &se->pre);
+ se->string_length = expr->ts.cl->backend_decl;
+ }
+
/* Is this the result of the enclosing procedure? */
this_array_result = (full_array_var && sym->attr.flavor == FL_PROCEDURE);
if (this_array_result
are NULL. Used by intrinsic size. */
unsigned data_not_needed:1;
+ /* If set, gfc_conv_function_call does not put byref calls into se->pre. */
+ unsigned no_function_call:1;
+
/* Scalarization parameters. */
struct gfc_se *parent;
struct gfc_ss *ss;
void gfc_generate_constructors (void);
/* Get the string length of an array constructor. */
-bool get_array_ctor_strlen (gfc_constructor *, tree *);
+bool get_array_ctor_strlen (stmtblock_t *, gfc_constructor *, tree *);
/* Generate a runtime error check. */
void gfc_trans_runtime_check (tree, const char *, stmtblock_t *, locus *);
--- /dev/null
+! { dg-do run }
+! Tests the fix for PR31219, in which the character length of
+! the functions in the array constructor was not being obtained
+! correctly and this caused an ICE.
+!
+! Contributed by Joost VandeVondele <jv244@cam.ac.uk>
+!
+ INTEGER :: J
+ CHARACTER(LEN = 8) :: str
+ J = 3
+ write (str,'(2A4)') (/( F(I, J), I = 1, 2)/)
+ IF (str .NE. " ODD EVE") call abort ()
+
+! Comment #1 from F-X Coudert (noted by T. Burnus) that
+! actually exercises a different part of the bug.
+ call gee( (/g (3)/) )
+
+CONTAINS
+ FUNCTION F (K,J) RESULT(I)
+ INTEGER :: K, J
+ CHARACTER(LEN = J) :: I
+ IF (MODULO (K, 2) .EQ. 0) THEN
+ I = "EVEN"
+ ELSE
+ I = "ODD"
+ ENDIF
+ END FUNCTION
+
+ function g(k) result(i)
+ integer :: k
+ character(len = k) :: i
+ i = '1234'
+ end function
+ subroutine gee(a)
+ character(*),dimension(1) :: a
+ if(len (a) /= 3) call abort ()
+ if(a(1) /= '123') call abort ()
+ end subroutine gee
+
+END