Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 2119828

Summary: gfortran incorrect code generation with -O1, works with -O0
Product: Red Hat Enterprise Linux 8 Reporter: Paulo Andrade <pandrade>
Component: gcc-toolset-11-gccAssignee: Marek Polacek <mpolacek>
Status: CLOSED UPSTREAM QA Contact: qe-baseos-tools-bugs
Severity: medium Docs Contact:
Priority: high    
Version: 8.6CC: ahajkova, fweimer, jakub, mpolacek, ohudlick, sipoyare, vrajput
Target Milestone: rcFlags: pm-rhel: mirror+
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-08-19 22:54:17 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

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.