[comp.sys.sgi] more IRIX 3.3.1 f77 -O2 bugs

glennrp@BRL.MIL (Glenn Randers-Pehrson, TBD|WMB) (01/15/91)

I have encountered several more bugs with the IRIX 3.3.1 f77 compiler
when used with -O2.  These are worse than the one I reported last week,
in that the compiler silently produces bogus code, instead of the core
dump.  I'll provide sources to anyone who is interested.

One class of statements causing problems involves the INQUIRE statement,
where the same logical variable appears in several INQUIRE statements,
as "isopen" in
        inquire(8,opened=isopen)
        if(isopen)....
        inquire(9,opened=isopen)
        if(isopen)...
The optimizer apparently does not recognize that the INQUIRE statement
assigns a new value to "isopen".

Another seems to involve an assumption by the programmer about storage
association, that the optimizer apparently did not recognize:

        subroutine sub(array))
        dimension array(6)
        common /a/ j,r(5)
        do 10 i=1,6
   10   r(i-1)=array(i)

The loop is supposed to copy the contents of the first element of "array"
into "j", without doing a float-to-integer conversion.  In the code, "j"
does get properly defined, but the optimizer gets goofed up later on in
the program, with entirely different variables.  When I rewrote this coding
to be a little more explicit, but still horrible to look at, then the problem
went away.

        subroutine sub(array))
        dimension array(6)
        common /a/ j,r(5)
        equivalence (rj,j)
        rj=array(1)
        do 10 i=2,5
   10   r(i-1)=array(i)

...Glenn Randers-Pehrson <glennrp@brl.mil>

glennrp@BRL.MIL (Glenn Randers-Pehrson, TBD|WMB) (01/15/91)

Here's a complete example of one of the bugs I described recently.
Hardware: IRIX 220GTX 
OS: IRIX 3.3.1

taylor.brl.mil> f77 -O1 inquirebug.f
taylor.brl.mil> a.out   # 8 is the correct answer
                8
taylor.brl.mil> f77 -O2 inquirebug.f
taylor.brl.mil> a.out   # 19 is wrong
               19



      program inquirebug
      open(19)
      open(20)
      call inqbug
      end

      subroutine inqbug
      save
      logical exists,isopen,inuse
      integer inqfile
      data inqfile/19/
c     find an available unit number
      isopen=.false.
      inquire(inqfile,exist=exists,err=70,iostat=junk)
      if(exists)inquire(inqfile,opened=isopen,err=70,iostat=junk)
      inuse=exists.and.isopen
      if(.not.inuse)go to 30
      do 20 i=8,99
      inqfile=i
      inquire(inqfile,exist=exists,err=70,iostat=junk)
      isopen=.false.
      if(exists)inquire(inqfile,opened=isopen,err=70,iostat=junk)
      inuse=exists.and.isopen
      if(.not.inuse)go to 30
 20   continue
      write(*,*)' inqbug: No available unit.'
      go to 70
 30   continue
      write(*,*)' inqbug:  unit=',inqfile
 65   close(inqfile,err=70)
 70   continue
      return
      end


The other program needs to be stripped down a bit more before I
would feel comfortable sending it out.  It's about 30K lines now. 

...Glenn Randers-Pehrson <glennrp@brl.mil>