aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Schlüter <tobi@gcc.gnu.org>2007-10-13 23:43:49 +0200
committerTobias Schlüter <tobi@gcc.gnu.org>2007-10-13 23:43:49 +0200
commit08ddab21215fba57be1ebdb495b9374953a6b679 (patch)
tree6b594a4e30b35f8484ca497241d85bc81bf45595
parentca94e524220617cadc4b32290474c50a0964fd46 (diff)
downloadgcc-08ddab21215fba57be1ebdb495b9374953a6b679.zip
gcc-08ddab21215fba57be1ebdb495b9374953a6b679.tar.gz
gcc-08ddab21215fba57be1ebdb495b9374953a6b679.tar.bz2
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
-rw-r--r--gcc/fortran/ChangeLog9
-rw-r--r--gcc/fortran/trans-array.c20
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/gfortran.dg/bounds_check_10.f9015
4 files changed, 50 insertions, 1 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 92a7570..eddaa91 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -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
diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index 2edc95b..4fb1fda 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -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;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 7cd56c3..83f025c 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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.
diff --git a/gcc/testsuite/gfortran.dg/bounds_check_10.f90 b/gcc/testsuite/gfortran.dg/bounds_check_10.f90
new file mode 100644
index 0000000..02101af
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/bounds_check_10.f90
@@ -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" }