public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/33525]  New: crash in if ( i .gt. 0 .and. a(i) .gt. 0 ) when a(0) is out of bounds
@ 2007-09-21 22:13 dusan dot turk at ijs dot si
  2007-09-21 23:03 ` [Bug fortran/33525] " kargl at gcc dot gnu dot org
  0 siblings, 1 reply; 2+ messages in thread
From: dusan dot turk at ijs dot si @ 2007-09-21 22:13 UTC (permalink / raw)
  To: gcc-bugs

the if statement crashes the code:
> 
>       program t
>       integer*4 i
>       real*4 a(10)
>       do i = 1, 10
>          a(i) = i
>       end do
>       i = 0
>       if ( i .gt. 0 .and. a(i) .gt. 0 ) then
>          i = i + 1
>          write(*,*) i
>       end if
>       end
> 
>  $ gfortran -fbounds-check -o t.exe t.f
>  $ t.exe 
> Fortran runtime error: Array reference out of bounds for array 'a',
> lower bound of dimension 1 exceeded (in file 't.f', at line 8)
With all other FORTAN compilers I've worked so far this does not happen as
after the first condition is not fulfilled the second is never tested.
This problem makes impossible to develope a program in GFROTRAN environment.


-- 
           Summary: crash in if ( i .gt. 0 .and. a(i) .gt. 0 ) when a(0) is
                    out of bounds
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: blocker
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dusan dot turk at ijs dot si


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


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

* [Bug fortran/33525] crash in if ( i .gt. 0 .and. a(i) .gt. 0 ) when a(0) is out of bounds
  2007-09-21 22:13 [Bug fortran/33525] New: crash in if ( i .gt. 0 .and. a(i) .gt. 0 ) when a(0) is out of bounds dusan dot turk at ijs dot si
@ 2007-09-21 23:03 ` kargl at gcc dot gnu dot org
  0 siblings, 0 replies; 2+ messages in thread
From: kargl at gcc dot gnu dot org @ 2007-09-21 23:03 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from kargl at gcc dot gnu dot org  2007-09-21 23:03 -------
The Fortran language does not guarantee the order of the
evaluation of the logical expression in your IF statement.
A fortran processor can try to evaluate "a(0) .gt. 0" before
the "i .gt. 0" expression.  Your code is broken and possibly
illegal Fortran.  Rewrite your code as you meant:

       i = 0
       if ( i .gt. 0) then
          if (a(i) .gt. 0 ) then
             i = i + 1
             write(*,*) i
          end if
       end if


-- 

kargl at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


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

end of thread, other threads:[~2007-09-21 23:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-09-21 22:13 [Bug fortran/33525] New: crash in if ( i .gt. 0 .and. a(i) .gt. 0 ) when a(0) is out of bounds dusan dot turk at ijs dot si
2007-09-21 23:03 ` [Bug fortran/33525] " kargl 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).