public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/34656]  New: modifies do loop variable
@ 2008-01-03 20:17 jv244 at cam dot ac dot uk
  2008-01-03 22:04 ` [Bug fortran/34656] " steven at gcc dot gnu dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: jv244 at cam dot ac dot uk @ 2008-01-03 20:17 UTC (permalink / raw)
  To: gcc-bugs

The following is non-standard and the compiler should probably generate a
warning/error with '-pedantic -std=f95', but does not do so with
gcc version 4.3.0 20080103 (experimental) [trunk revision 131300] (GCC)

PROGRAM test
IMPLICIT NONE
INTEGER :: i
DO i=1,100
   CALL do_something()
ENDDO
CONTAINS
 SUBROUTINE do_something()
 IMPLICIT NONE
 DO i=1,10
 ENDDO
 END SUBROUTINE do_something
END PROGRAM test


-- 
           Summary: modifies do loop variable
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jv244 at cam dot ac dot uk


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34656


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/34656] modifies do loop variable
  2008-01-03 20:17 [Bug fortran/34656] New: modifies do loop variable jv244 at cam dot ac dot uk
@ 2008-01-03 22:04 ` steven at gcc dot gnu dot org
  2008-01-04  7:17 ` jv244 at cam dot ac dot uk
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: steven at gcc dot gnu dot org @ 2008-01-03 22:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from steven at gcc dot gnu dot org  2008-01-03 21:51 -------
This is almost impossible to diagnose.  Do you know of any compiler that
detects this?

The only way I see to diagnose this, is to mark all do loop variables as such,
and warn about all assignments to such variables in contained functions.  But
that would result in false positives for e.g.

PROGRAM test
IMPLICIT NONE
INTEGER :: i
DO i=1,100
   CALL do_nothing()
ENDDO
CALL do_something()
CONTAINS
 SUBROUTINE do_something()
 IMPLICIT NONE
 DO i=1,10
 ENDDO
 END SUBROUTINE do_something
 SUBROUTINE do_nothing()
 IMPLICIT NONE
 END SUBROUTINE do_nothing
END PROGRAM test

which also seems undesirable... Thoughts?


-- 

steven 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         |2008-01-03 21:51:49
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34656


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/34656] modifies do loop variable
  2008-01-03 20:17 [Bug fortran/34656] New: modifies do loop variable jv244 at cam dot ac dot uk
  2008-01-03 22:04 ` [Bug fortran/34656] " steven at gcc dot gnu dot org
@ 2008-01-04  7:17 ` jv244 at cam dot ac dot uk
  2008-01-04  7:23 ` burnus at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jv244 at cam dot ac dot uk @ 2008-01-04  7:17 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from jv244 at cam dot ac dot uk  2008-01-04 07:02 -------
(In reply to comment #1)
> This is almost impossible to diagnose.  Do you know of any compiler that
> detects this?

I think that lahey detects this at runtime. Almost all compilers detect the
simple case of directly (i.e. not through a call) modifing the variable. I
think it is actually a rather useful warning/error since it is an easy mistake
to make.

> 
> The only way I see to diagnose this, is to mark all do loop variables as such,
> and warn about all assignments to such variables in contained functions.  
> which also seems undesirable... Thoughts?
> 

I don't think this would be good enough without the extra check that this
contained function is called from within the corresponding loop. In principle
all information is available in this case, but I guess it might be difficult to
extract.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34656


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/34656] modifies do loop variable
  2008-01-03 20:17 [Bug fortran/34656] New: modifies do loop variable jv244 at cam dot ac dot uk
  2008-01-03 22:04 ` [Bug fortran/34656] " steven at gcc dot gnu dot org
  2008-01-04  7:17 ` jv244 at cam dot ac dot uk
@ 2008-01-04  7:23 ` burnus at gcc dot gnu dot org
  2008-01-04  9:36 ` tkoenig at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: burnus at gcc dot gnu dot org @ 2008-01-04  7:23 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from burnus at gcc dot gnu dot org  2008-01-04 07:12 -------
NAG f95 does not even detect this at run time! However, I think it should be
relatively easyly detectable at run time.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34656


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/34656] modifies do loop variable
  2008-01-03 20:17 [Bug fortran/34656] New: modifies do loop variable jv244 at cam dot ac dot uk
                   ` (2 preceding siblings ...)
  2008-01-04  7:23 ` burnus at gcc dot gnu dot org
@ 2008-01-04  9:36 ` tkoenig at gcc dot gnu dot org
  2009-03-28 21:39 ` burnus at gcc dot gnu dot org
  2009-03-28 21:40 ` burnus at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2008-01-04  9:36 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from tkoenig at gcc dot gnu dot org  2008-01-04 09:20 -------
We don't violate a constraint by not detecting this,
but it sure would be a useful enhancement.


-- 

tkoenig at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
           Keywords|accepts-invalid             |diagnostic


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34656


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/34656] modifies do loop variable
  2008-01-03 20:17 [Bug fortran/34656] New: modifies do loop variable jv244 at cam dot ac dot uk
                   ` (3 preceding siblings ...)
  2008-01-04  9:36 ` tkoenig at gcc dot gnu dot org
@ 2009-03-28 21:39 ` burnus at gcc dot gnu dot org
  2009-03-28 21:40 ` burnus at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-03-28 21:39 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from burnus at gcc dot gnu dot org  2009-03-28 21:39 -------
Subject: Bug 34656

Author: burnus
Date: Sat Mar 28 21:39:26 2009
New Revision: 145210

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=145210
Log:
2009-03-28  Tobias Burnus  <burnus@net-b.de>

        PR fortran/34656
        * trans-stmt.c (gfc_trans_simple_do, gfc_trans_do):
        Add GFC_RTCHECK_DO support.
        * option.c (gfc_handle_runtime_check_option): Enable
        * GFC_RTCHECK_DO.
        * invoke.texi (-fcheck): Document "do" option.


Added:
    trunk/gcc/testsuite/gfortran.dg/do_check_1.f90
    trunk/gcc/testsuite/gfortran.dg/do_check_2.f90
    trunk/gcc/testsuite/gfortran.dg/do_check_3.f90
    trunk/gcc/testsuite/gfortran.dg/do_check_4.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/invoke.texi
    trunk/gcc/fortran/options.c
    trunk/gcc/fortran/trans-stmt.c
    trunk/gcc/testsuite/ChangeLog


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34656


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/34656] modifies do loop variable
  2008-01-03 20:17 [Bug fortran/34656] New: modifies do loop variable jv244 at cam dot ac dot uk
                   ` (4 preceding siblings ...)
  2009-03-28 21:39 ` burnus at gcc dot gnu dot org
@ 2009-03-28 21:40 ` burnus at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-03-28 21:40 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from burnus at gcc dot gnu dot org  2009-03-28 21:40 -------
FIXED on the trunk (4.5):

$ gfortran -fcheck=do test.f90
$ ./a.out
At line 4 of file test.f90
Fortran runtime error: Loop variable has been modified

The error location is not the best but it works reliably and without adding a
check after each statement. (NAG f95 gives a better line for the error message
for such violations, but it fails to detect this violation.)


-- 

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34656


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2009-03-28 21:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-03 20:17 [Bug fortran/34656] New: modifies do loop variable jv244 at cam dot ac dot uk
2008-01-03 22:04 ` [Bug fortran/34656] " steven at gcc dot gnu dot org
2008-01-04  7:17 ` jv244 at cam dot ac dot uk
2008-01-04  7:23 ` burnus at gcc dot gnu dot org
2008-01-04  9:36 ` tkoenig at gcc dot gnu dot org
2009-03-28 21:39 ` burnus at gcc dot gnu dot org
2009-03-28 21:40 ` burnus 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).