public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/28439]  New: Multiple evaluations of arithmetic if condition
@ 2006-07-19 16:59 mfpasik at sandia dot gov
  2006-07-19 20:33 ` [Bug fortran/28439] " kargl at gcc dot gnu dot org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: mfpasik at sandia dot gov @ 2006-07-19 16:59 UTC (permalink / raw)
  To: gcc-bugs

The expression/condition in an arithmetic if statement appears to be evaluated
multiple times when it is zero or negative. This is particularly bad when the
expression is a function that depends on input or has state associated with it.

Example:

      program lll

      integer myfunc

      do 99 i=1,10
      if (myfunc(0)) 10,20,30

 10   write (6,*) 'negative'
      goto 99

 20   write (6,*) 'zero'
      goto 99

 30   write (6,*) 'positive'
      goto 99

 99   continue
      end


      integer function myfunc(int)
      integer value
      read (5,*) value
      myfunc = value
      return
      end

Sample input/output:

1
 positive
0
3
 zero
-1
3
 zero
4
 positive
0
0
 zero

Workaround:

Introduce a temporary expression for the if test condition/expression or
convert obsolete arithmetic if to an if-then-else statement.


-- 
           Summary: Multiple evaluations of arithmetic if condition
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mfpasik at sandia dot gov
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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


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

end of thread, other threads:[~2006-07-25 23:32 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-19 16:59 [Bug fortran/28439] New: Multiple evaluations of arithmetic if condition mfpasik at sandia dot gov
2006-07-19 20:33 ` [Bug fortran/28439] " kargl at gcc dot gnu dot org
2006-07-19 23:03 ` steven at gcc dot gnu dot org
2006-07-19 23:03 ` steven at gcc dot gnu dot org
2006-07-19 23:06 ` pinskia at gcc dot gnu dot org
2006-07-19 23:08 ` steven at gcc dot gnu dot org
2006-07-20  4:37 ` kargl at gcc dot gnu dot org
2006-07-21 23:39 ` steven at gcc dot gnu dot org
2006-07-22  2:01 ` kargl at gcc dot gnu dot org
2006-07-22 17:55 ` kargl at gcc dot gnu dot org
2006-07-22 17:58 ` [Bug fortran/28439] [4.1 only] " kargl at gcc dot gnu dot org
2006-07-24 16:54 ` kargl at gcc dot gnu dot org
2006-07-25 23:31 ` kargl at gcc dot gnu dot org
2006-07-25 23:32 ` 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).