public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/30655] New: Undue out-of-bounds warning
@ 2007-01-31 14:18 fxcoudert at gcc dot gnu dot org
2007-01-31 18:13 ` [Bug fortran/30655] " tkoenig at gcc dot gnu dot org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-01-31 14:18 UTC (permalink / raw)
To: gcc-bugs
gfortran should not report an out-of-bounds access on the following code:
$ cat a.f90
integer i(12), j
j = -1
i(0:j) = 42
end
$ gfortran a.f90
a.f90:3.4:
i(0:j) = 42
1
Warning: Array reference at (1) is out of bounds
Compiling with -fbounds-check and running it doesn't error, which means the
-fbounds-check code is generated fine. But, somewhere, the front-end is
over-zealous (it doesn't know about stride). I thought I had that fixed at some
point...
--
Summary: Undue out-of-bounds warning
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Keywords: diagnostic
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: fxcoudert at gcc dot gnu dot org
OtherBugsDependingO 27766
nThis:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30655
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/30655] Undue out-of-bounds warning
2007-01-31 14:18 [Bug fortran/30655] New: Undue out-of-bounds warning fxcoudert at gcc dot gnu dot org
@ 2007-01-31 18:13 ` tkoenig at gcc dot gnu dot org
2007-01-31 22:06 ` fxcoudert at gcc dot gnu dot org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2007-01-31 18:13 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from tkoenig at gcc dot gnu dot org 2007-01-31 18:13 -------
Really?
This is fine:
integer i(12), j
i(0:-1) = 42
end
In your test case, the compiler has a hard time detecting the
value of j, and the lower bound would be incorrect if j >=1.
--
tkoenig at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |tkoenig at gcc dot gnu dot
| |org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30655
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/30655] Undue out-of-bounds warning
2007-01-31 14:18 [Bug fortran/30655] New: Undue out-of-bounds warning fxcoudert at gcc dot gnu dot org
2007-01-31 18:13 ` [Bug fortran/30655] " tkoenig at gcc dot gnu dot org
@ 2007-01-31 22:06 ` fxcoudert at gcc dot gnu dot org
2007-03-14 10:48 ` fxcoudert at gcc dot gnu dot org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-01-31 22:06 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from fxcoudert at gcc dot gnu dot org 2007-01-31 22:05 -------
Around resolve.c:2518:
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))
when I wrote that code, I stupidly assumed that compare_bound(...) != CMP_GT
was equivalent to compare_bound(...) == CMP_LT || compare_bound(...) == CMP_EQ,
and it's wrong because there's also CMP_UNKNOWN!
The following trivial patch fixes it (I also create a variable to hold the
comparison of AR_START and AR_END, because we use it multiple times).
Index: resolve.c
===================================================================
--- resolve.c (revision 121280)
+++ resolve.c (working copy)
@@ -2499,48 +2499,51 @@
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;
- }
+ 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 (comp_start_end == CMP_EQ
+ && (compare_bound (AR_START, as->lower[i]) == CMP_LT
+ || compare_bound (AR_START, as->upper[i]) == CMP_GT))
+ goto bound;
+
+ if (((compare_bound_int (ar->stride[i], 0) == CMP_GT
+ || ar->stride[i] == NULL)
+ && (comp_start_end == CMP_LT || comp_start_end == CMP_EQ))
+ || (compare_bound_int (ar->stride[i], 0) == CMP_LT
+ && (comp_start_end == CMP_GT || comp_start_end == CMP_EQ)))
+ {
+ if (compare_bound (AR_START, as->lower[i]) == CMP_LT)
goto bound;
- }
- }
- mpz_clear (last_value);
+ if (compare_bound (AR_START, as->upper[i]) == CMP_GT)
+ goto bound;
+ }
+ 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:
--
fxcoudert at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2007-01-31 22:05:59
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30655
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/30655] Undue out-of-bounds warning
2007-01-31 14:18 [Bug fortran/30655] New: Undue out-of-bounds warning fxcoudert at gcc dot gnu dot org
2007-01-31 18:13 ` [Bug fortran/30655] " tkoenig at gcc dot gnu dot org
2007-01-31 22:06 ` fxcoudert at gcc dot gnu dot org
@ 2007-03-14 10:48 ` fxcoudert at gcc dot gnu dot org
2007-03-24 20:20 ` fxcoudert at gcc dot gnu dot org
2007-03-24 20:21 ` fxcoudert at gcc dot gnu dot org
4 siblings, 0 replies; 6+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-03-14 10:48 UTC (permalink / raw)
To: gcc-bugs
--
fxcoudert at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |fxcoudert at gcc dot gnu dot
|dot org |org
Status|NEW |ASSIGNED
Last reconfirmed|2007-01-31 22:05:59 |2007-03-14 10:48:06
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30655
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/30655] Undue out-of-bounds warning
2007-01-31 14:18 [Bug fortran/30655] New: Undue out-of-bounds warning fxcoudert at gcc dot gnu dot org
` (2 preceding siblings ...)
2007-03-14 10:48 ` fxcoudert at gcc dot gnu dot org
@ 2007-03-24 20:20 ` fxcoudert at gcc dot gnu dot org
2007-03-24 20:21 ` fxcoudert at gcc dot gnu dot org
4 siblings, 0 replies; 6+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-03-24 20:20 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from fxcoudert at gcc dot gnu dot org 2007-03-24 20:20 -------
Subject: Bug 30655
Author: fxcoudert
Date: Sat Mar 24 20:19:51 2007
New Revision: 123187
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=123187
Log:
PR fortran/30655
* expr.c (check_dimension): Fix logic of comparisons.
* gfortran.dg/bounds_check_6.f90: New test.
Added:
trunk/gcc/testsuite/gfortran.dg/bounds_check_6.f90
Modified:
trunk/gcc/fortran/ChangeLog
trunk/gcc/fortran/resolve.c
trunk/gcc/testsuite/ChangeLog
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30655
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/30655] Undue out-of-bounds warning
2007-01-31 14:18 [Bug fortran/30655] New: Undue out-of-bounds warning fxcoudert at gcc dot gnu dot org
` (3 preceding siblings ...)
2007-03-24 20:20 ` fxcoudert at gcc dot gnu dot org
@ 2007-03-24 20:21 ` fxcoudert at gcc dot gnu dot org
4 siblings, 0 replies; 6+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-03-24 20:21 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from fxcoudert at gcc dot gnu dot org 2007-03-24 20:21 -------
Fixed on 4.3, will not backport.
--
fxcoudert at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
Target Milestone|--- |4.3.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30655
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2007-03-24 20:21 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-31 14:18 [Bug fortran/30655] New: Undue out-of-bounds warning fxcoudert at gcc dot gnu dot org
2007-01-31 18:13 ` [Bug fortran/30655] " tkoenig at gcc dot gnu dot org
2007-01-31 22:06 ` fxcoudert at gcc dot gnu dot org
2007-03-14 10:48 ` fxcoudert at gcc dot gnu dot org
2007-03-24 20:20 ` fxcoudert at gcc dot gnu dot org
2007-03-24 20:21 ` fxcoudert at gcc dot gnu dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).