OSDN Git Service

2007-10-13 Tobias Schlueter <tobi@gcc.gnu.org>
authortobi <tobi@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 13 Oct 2007 21:43:49 +0000 (21:43 +0000)
committertobi <tobi@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 13 Oct 2007 21:43:49 +0000 (21:43 +0000)
    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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@129286 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/fortran/ChangeLog
gcc/fortran/trans-array.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/bounds_check_10.f90 [new file with mode: 0644]

index 92a7570..eddaa91 100644 (file)
@@ -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
index 2edc95b..4fb1fda 100644 (file)
@@ -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;
index 7cd56c3..83f025c 100644 (file)
@@ -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 (file)
index 0000000..02101af
--- /dev/null
@@ -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" }