[Bug fortran/28439] New: Multiple evaluations of arithmetic if condition

mfpasik at sandia dot gov gcc-bugzilla@gcc.gnu.org
Wed Jul 19 16:59:00 GMT 2006


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



More information about the Gcc-bugs mailing list