aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran
diff options
context:
space:
mode:
authorFrancois-Xavier Coudert <fxcoudert@gcc.gnu.org>2007-03-24 20:19:51 +0000
committerFrançois-Xavier Coudert <fxcoudert@gcc.gnu.org>2007-03-24 20:19:51 +0000
commitd912240d907b6b595e27fc8c3cf027dfc10dd359 (patch)
tree4e436b9650956b3743ada17633b4b415416f5ccd /gcc/fortran
parent13f703423a3b5cc31172d60f2d5e91ad04d9c91b (diff)
downloadgcc-d912240d907b6b595e27fc8c3cf027dfc10dd359.zip
gcc-d912240d907b6b595e27fc8c3cf027dfc10dd359.tar.gz
gcc-d912240d907b6b595e27fc8c3cf027dfc10dd359.tar.bz2
re PR fortran/30655 (Undue out-of-bounds warning)
PR fortran/30655 * expr.c (check_dimension): Fix logic of comparisons. * gfortran.dg/bounds_check_6.f90: New test. From-SVN: r123187
Diffstat (limited to 'gcc/fortran')
-rw-r--r--gcc/fortran/ChangeLog5
-rw-r--r--gcc/fortran/resolve.c71
2 files changed, 43 insertions, 33 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 99c67fc..d99b31f 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,8 @@
+2007-03-24 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
+
+ PR fortran/30655
+ * expr.c (check_dimension): Fix logic of comparisons.
+
2007-03-24 Paul Thomas <pault@gcc.gnu.org>
PR fortran/31215
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index a72047e..164a0cb 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -2507,48 +2507,53 @@ check_dimension (int i, gfc_array_ref *ar, gfc_array_spec *as)
break;
case AR_SECTION:
- if (compare_bound_int (ar->stride[i], 0) == CMP_EQ)
- {
- gfc_error ("Illegal stride of zero at %L", &ar->c_where[i]);
- return FAILURE;
- }
-
+ {
#define AR_START (ar->start[i] ? ar->start[i] : as->lower[i])
#define AR_END (ar->end[i] ? ar->end[i] : as->upper[i])
- if (compare_bound (AR_START, AR_END) == CMP_EQ
- && (compare_bound (AR_START, as->lower[i]) == CMP_LT
- || compare_bound (AR_START, as->upper[i]) == CMP_GT))
- goto bound;
+ comparison comp_start_end = compare_bound (AR_START, AR_END);
- if (((compare_bound_int (ar->stride[i], 0) == CMP_GT
- || ar->stride[i] == NULL)
- && compare_bound (AR_START, AR_END) != CMP_GT)
- || (compare_bound_int (ar->stride[i], 0) == CMP_LT
- && compare_bound (AR_START, AR_END) != CMP_LT))
- {
- if (compare_bound (AR_START, as->lower[i]) == CMP_LT)
- goto bound;
- if (compare_bound (AR_START, as->upper[i]) == CMP_GT)
- goto bound;
- }
+ /* Check for zero stride, which is not allowed. */
+ if (compare_bound_int (ar->stride[i], 0) == CMP_EQ)
+ {
+ gfc_error ("Illegal stride of zero at %L", &ar->c_where[i]);
+ return FAILURE;
+ }
- mpz_init (last_value);
- if (compute_last_value_for_triplet (AR_START, AR_END, ar->stride[i],
- last_value))
- {
- if (compare_bound_mpz_t (as->lower[i], last_value) == CMP_GT
- || compare_bound_mpz_t (as->upper[i], last_value) == CMP_LT)
- {
- mpz_clear (last_value);
+ /* if start == len || (stride > 0 && start < len)
+ || (stride < 0 && start > len),
+ then the array section contains at least one element. In this
+ case, there is an out-of-bounds access if
+ (start < lower || start > upper). */
+ if (compare_bound (AR_START, AR_END) == CMP_EQ
+ || ((compare_bound_int (ar->stride[i], 0) == CMP_GT
+ || ar->stride[i] == NULL) && comp_start_end == CMP_LT)
+ || (compare_bound_int (ar->stride[i], 0) == CMP_LT
+ && comp_start_end == CMP_GT))
+ {
+ if (compare_bound (AR_START, as->lower[i]) == CMP_LT
+ || compare_bound (AR_START, as->upper[i]) == CMP_GT)
goto bound;
- }
- }
- mpz_clear (last_value);
+ }
+
+ /* If we can compute the highest index of the array section,
+ then it also has to be between lower and upper. */
+ mpz_init (last_value);
+ if (compute_last_value_for_triplet (AR_START, AR_END, ar->stride[i],
+ last_value))
+ {
+ if (compare_bound_mpz_t (as->lower[i], last_value) == CMP_GT
+ || compare_bound_mpz_t (as->upper[i], last_value) == CMP_LT)
+ {
+ mpz_clear (last_value);
+ goto bound;
+ }
+ }
+ mpz_clear (last_value);
#undef AR_START
#undef AR_END
-
+ }
break;
default: