re PR fortran/33254 (Diagnose different string lengths in array constructors at run time)
2007-10-13 Tobias Schlueter <tobi@gcc.gnu.org> Paul Thomas <pault@gcc.gnu.org> PR fortran/33254 PR fortran/33727 fortran/ * 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. testsuite/ * bounds_check_10.f90: New. Co-Authored-By: Paul Thomas <pault@gcc.gnu.org> From-SVN: r129286
This commit is contained in:
parent
ca94e52422
commit
08ddab2121
4 changed files with 50 additions and 1 deletions
|
@ -1,3 +1,12 @@
|
|||
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
|
||||
|
|
|
@ -1340,7 +1340,7 @@ get_array_ctor_var_strlen (gfc_expr * expr, tree * len)
|
|||
|
||||
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);
|
||||
|
@ -1413,6 +1413,7 @@ bool
|
|||
get_array_ctor_strlen (stmtblock_t *block, gfc_constructor * c, tree * len)
|
||||
{
|
||||
bool is_const;
|
||||
tree first_len = NULL_TREE;
|
||||
|
||||
is_const = TRUE;
|
||||
|
||||
|
@ -1447,6 +1448,23 @@ get_array_ctor_strlen (stmtblock_t *block, gfc_constructor * c, tree * len)
|
|||
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;
|
||||
|
|
|
@ -1,3 +1,10 @@
|
|||
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.
|
||||
|
|
15
gcc/testsuite/gfortran.dg/bounds_check_10.f90
Normal file
15
gcc/testsuite/gfortran.dg/bounds_check_10.f90
Normal file
|
@ -0,0 +1,15 @@
|
|||
! { 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" }
|
Loading…
Add table
Reference in a new issue