+2007-10-13 Tobias Schlüter <tobi@gcc.gnu.org>
+ Paul Thomas <pault@gcc.gnu.org>
+
+ PR fortran/33254
+ PR fortran/33727
+ * trans-array.c (get_array_ctor_var_strlen): Check upper bound for
+ constness instead of lower bound.
+ (get_array_ctor_strlen): Add bounds-checking code.
+
2007-10-12 Paul Thomas <pault@gcc.gnu.org>
PR fortran/33542
case REF_SUBSTRING:
if (ref->u.ss.start->expr_type != EXPR_CONSTANT
- || ref->u.ss.start->expr_type != EXPR_CONSTANT)
+ || ref->u.ss.end->expr_type != EXPR_CONSTANT)
break;
mpz_init_set_ui (char_len, 1);
mpz_add (char_len, char_len, ref->u.ss.end->value.integer);
get_array_ctor_strlen (stmtblock_t *block, gfc_constructor * c, tree * len)
{
bool is_const;
+ tree first_len = NULL_TREE;
is_const = TRUE;
get_array_ctor_all_strlen (block, c->expr, len);
break;
}
+ if (flag_bounds_check)
+ {
+ if (!first_len)
+ first_len = *len;
+ else
+ {
+ /* Verify that all constructor elements are of the same
+ length. */
+ tree cond = fold_build2 (NE_EXPR, boolean_type_node,
+ first_len, *len);
+ gfc_trans_runtime_check
+ (cond, block, &c->expr->where,
+ "Different CHARACTER lengths (%ld/%ld) in array constructor",
+ fold_convert (long_integer_type_node, first_len),
+ fold_convert (long_integer_type_node, *len));
+ }
+ }
}
return is_const;
+2007-10-13 Tobias Schlüter <tobi@gcc.gnu.org>
+ Paul Thomas <pault@gcc.gnu.org>
+
+ PR fortran/33254
+ PR fortran/33727
+ * bounds_check_10.f90: New.
+
2007-10-13 David Edelsohn <edelsohn@gnu.org>
* gcc.target/powerpc/parity-1.c: POWER5 feature, not POWER6.
--- /dev/null
+! { dg-do run }
+! { dg-options "-fbounds-check" }
+! { dg-shouldfail "Different CHARACTER lengths" }
+! PR fortran/33254: No bounds checking for array constructors
+program array_char
+implicit none
+character (len=2) :: x, y
+character (len=2) :: z(3)
+x = "a "
+y = "cd"
+z = [y(1:1), x(1:len(trim(x)))] ! should work
+z = [trim(x), trim(y), "aaaa"] ! [ "a", "cd", "aaaa" ] should catch first error
+end program array_char
+
+! { dg-output "Different CHARACTER lengths .1/2. in array constructor" }