https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127179
Bug ID: 127179
Summary: [OOP] ICE in gfc_conv_structure for CLASS pointer
component with an initial data target
Product: gcc
Version: 17.0
URL: https://godbolt.org/z/Yehhv1jx1
Status: UNCONFIRMED
Keywords: ice-on-valid-code
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: federico.perini at gmail dot com
Target Milestone: ---
Created attachment 65472
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=65472&action=edit
test program
Default initialization of a polymorphic pointer derived-type component to a
module variable with the TARGET attribute causes an ICE.
The equivalent non-polymorphic component compiles fine, as does a polymorphic
pointer variable (rather than component) with the same initialization.
```
module m
type :: t; end type
type(t), target :: static
end module m
module n
use m
type :: q
class(t), pointer :: r => static ! ICE
!type(t), pointer :: s => static ! works
end type q
end module n
program p
use n
! class(t), pointer :: r => static ! works
stop 0
end program
```
causes
```
example.f90:7:12:
7 | end module m
| 1
internal compiler error: in gfc_conv_structure, at fortran/trans-expr.cc:10537
0x21694d8 diagnostics::context::diagnostic_impl(...)
0x2161fcb internal_error(char const*, ...)
0x7dda34 fancy_abort(char const*, int, char const*)
0x9780df gfc_conv_initializer(gfc_expr*, gfc_typespec*, tree_node*, bool, bool,
bool)
0x97852a gfc_conv_structure(gfc_se*, gfc_expr*, int)
0x9780df gfc_conv_initializer(gfc_expr*, gfc_typespec*, tree_node*, bool, bool,
bool)
0x95d89a gfc_get_symbol_decl(gfc_symbol*)
0x96138f gfc_generate_module_vars(gfc_namespace*)
0x930f4f gfc_generate_module_code(gfc_namespace*)
0x8c360d gfc_parse_file()
```
Note the error is reported at `end module m` (the wrong module — the offending
component is in module n), which suggests the initializer is being evaluated
while emitting the _vtab/module variables of m.
The code appears to be valid data-pointer-initialization: static is a
nonallocatable, nonpointer variable with the TARGET and SAVE (implicit, module)
attributes, and it is type-compatible with the declared type of r.
gfc_conv_initializer presumably needs to build the class container
(_data/_vptr) here rather than falling through to gfc_conv_structure with a
non-derived-type expression.
Godbolt: https://godbolt.org/z/Yehhv1jx1
Thank you,
Federico