https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127077
Bug ID: 127077
Summary: ICE with imported overloaded operator in named BLOCK
containing EXIT
Product: gcc
Version: 15.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: sjmclimate at gmail dot com
Target Milestone: ---
The valid Fortran program below causes gfortran to produce an internal compiler
error.
Compile with:
gfortran -c -std=f2008 gfortran_block_operator_ice.f90
Expected result:
Successful compilation
Actual result:
f951.exe: internal compiler error: Segmentation fault
The problem occurs at -O0, so it does not appear to depend on optimization.
I have reproduced the problem with gfortran 11.5, 12.2, and 15.2 on Windows
using MinGW builds.
Two changes independently avoid the ICE:
1. Replacing the named BLOCK/END BLOCK construct with a named DO/END DO
construct.
2. Replacing the imported overloaded /= operator with an intrinsic comparison.
The code below is a standalone 37-line reproducer.
! Standalone reproducer for a gfortran 15.2.0 internal compiler error.
!
! Compile with:
! gfortran -c -std=f2008 gfortran_block_operator_ice.f90
!
! Expected: successful compilation.
! Actual: f951.exe: internal compiler error: Segmentation fault
!
! Workaround: replace the named BLOCK/END BLOCK with DO/END DO.
module types_m
implicit none
type t
integer :: i
end type t
interface operator(/=)
module procedure not_equal
end interface
contains
logical function not_equal(a, b)
type(t), intent(in) :: a, b
not_equal = a%i /= b%i
end function not_equal
end module types_m
module reproducer_m
use types_m, only: t, operator(/=)
implicit none
contains
integer function compare(a, b) result(status)
type(t), intent(in) :: a, b
check: block
if (a /= b) exit check
status = 0
return
end block check
status = 1
end function compare
end module reproducer_m