Bug 2119828 - gfortran incorrect code generation with -O1, works with -O0
Summary: gfortran incorrect code generation with -O1, works with -O0
Keywords:
Status: CLOSED UPSTREAM
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: gcc-toolset-11-gcc
Version: 8.6
Hardware: All
OS: Linux
high
medium
Target Milestone: rc
: ---
Assignee: Marek Polacek
QA Contact: qe-baseos-tools-bugs
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2022-08-19 14:26 UTC by Paulo Andrade
Modified: 2023-07-18 14:19 UTC (History)
7 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2022-08-19 22:54:17 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
GNU Compiler Collection 106692 0 P3 UNCONFIRMED [10/11/12/13 Regression] Cray pointer comparison wrongly optimized away 2022-08-19 22:54:17 UTC
Red Hat Issue Tracker RHELPLAN-131753 0 None None None 2022-08-19 14:34:02 UTC

Description Paulo Andrade 2022-08-19 14:26:58 UTC
Reproducer:

"""
$ cat sk.f
      program test
c         this program tests memory allocation

c     write(*,*)"Enter an interger higher than 0"
c     read(*,*)k
      k=1
      call  test_cray(k)
      end

      subroutine test_cray(k)
c        integer*8 ptrzz1
        pointer(ptrzz1 , zz1)
        ptrzz1=0
c        ptrzz1=loc(zz1)
        write(*,*)"   ptrzz1: ",ptrzz1
        if (ptrzz1 .ne. 0) then
          write(*,*)"   ptrzz1 ne zero in the calling routine"
        else
          write(*,*)"   ptrzz1 eq zero in the calling routine"
          call shape_cray(zz1)
          write(*,*)"*** Returning from shape_cray"
        end if
      end


      subroutine shape_cray(zz1)
        pointer(ptrzz , zz)
        ptrzz=loc(zz1)
        if (ptrzz .ne. 0) then
          write(*,*)"      ptrzz - loc(zz1)- ne zero in the called routine"
          write(*,*)"      ptrzz: ",ptrzz
        else
          write(*,*)"      ptrzz - loc(zz1) eq zero in the called routine"
          write(*,*)"      ptrzz: ",ptrzz
        end if
c        write(*,*)"   ptrzz: ",ptrzz
      end


$ gfortran -frecursive -fPIC -ffixed-line-length-132 -fautomatic -fcray-pointer -O1 -o test sk.f
$ ./test 
    ptrzz1:                     0
    ptrzz1 eq zero in the calling routine
       ptrzz - loc(zz1)- ne zero in the called routine
       ptrzz:                     0
 *** Returning from shape_cray
"""

  If compiled with -O0 it works as expected:
"""
$ gfortran -frecursive -fPIC -ffixed-line-length-132 -fautomatic -fcray-pointer -O0 -o test sk.f
$ ./test 
    ptrzz1:                     0
    ptrzz1 eq zero in the calling routine
       ptrzz - loc(zz1) eq zero in the called routine
       ptrzz:                     0
 *** Returning from shape_cray
"""

Comment 1 Marek Polacek 2022-08-19 22:27:11 UTC
Reproduced.  Started with r238754.  Reduced test:

      program test
      k=1
      call  test_cray(k)
      end

      subroutine test_cray(k)
        pointer(ptrzz1 , zz1)
        ptrzz1=0
        if (ptrzz1 .ne. 0) then
          call abort()
        else
          call shape_cray(zz1)
        end if
      end

      subroutine shape_cray(zz1)
        pointer(ptrzz , zz)
        ptrzz=loc(zz1)
        if (ptrzz .ne. 0) then
          call abort()
        end if
      end

I have to file an upstream bug.

Comment 2 Marek Polacek 2022-08-19 22:54:17 UTC
Upstream PR filed.  This needs to be dealt with in upstream first.


Note You need to log in before you can comment on or make changes to this bug.