https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126909
Bug ID: 126909
Summary: Lost statement label in a program with a CONTAINS
section
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: kargl at gcc dot gnu.org
Target Milestone: ---
gfortran seems to lose the statement label on the end-program-stmt
if a CONTAINS section exists. This bug was found by an issue in
the lfortran bug tracker, but extended to have dead code that the
code branches over.
Consider the following code in a file named t2.f90,
subroutine sub()
print *, 'Entered sub()'
goto 11
print *, 'Dead code'
11 end subroutine sub
program lost
print *, "Calling sub()"
call sub()
goto 10
print *, 'More dead code'
10 end program lost
% gfcx -o z t2.f90 && ./z
Calling sub()
Entered sub()
% flang21 -o z t2.f90 && ./z
Calling sub()
Entered sub()
The functionally equivalent program with an internal subprogram is
program lost
print *, "Calling sub()"
call sub()
goto 10
print *, 'More Dead code'
contains
subroutine sub()
print *, 'Entered sub()'
goto 11
print *, 'Dead code'
11 end subroutine sub
10 end program lost
% gfcx -o z t2.f90 && ./z
t2.f90:17:10:
17 | goto 10
| 1
Error: Label 10 referenced at (1) is never defined
% flang21 -o z t2.f90 && ./z
Calling sub()
Entered sub()