https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122452
Bug ID: 122452
Summary: [16 Regression] [PDT] ICE on use of
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: damian at archaeologic dot codes
Target Milestone: ---
gfortran 13.4.0, 14.3.0, and 15.2.0 compile the code below with no warning or
error -- as do the NAG and Intel (ifx) compilers. The LLVM Flang compiler
issues a warning that I believe is incorrect. I'll paste that warning at the
bottom of this message.
$ cat reproducer.f90
module tensor_m
implicit none
type tensor_t(k)
integer, kind :: k = kind(0.)
real(k), allocatable, private :: values_(:)
end type
interface tensor_t
module function construct_default_real(values) result(tensor)
implicit none
real values(:)
type(tensor_t) tensor
end function
module function construct_double_precision(values) result(tensor)
implicit none
double precision values(:)
type(tensor_t(kind(0D0))) tensor
end function
end interface
contains
function const()
type(tensor_t(kind(0D0))) const
const = tensor_t([0D0])
end function
end module
$ gfortran -c reproducer.f90
reproducer.f90:26:27:
26 | const = tensor_t([0D0])
| 1
internal compiler error: in fold_convert_loc, at fold-const.cc:2809
0x262363b internal_error(char const*, ...)
../../trunk/gcc/diagnostic-global-context.cc:787
0xa09f26 fancy_abort(char const*, int, char const*)
../../trunk/gcc/diagnostics/context.cc:1806
0x819126 fold_convert_loc(unsigned long, tree_node*, tree_node*)
../../trunk/gcc/fold-const.cc:2809
0xb9242c gfc_trans_scalar_assign(gfc_se*, gfc_se*, gfc_typespec, bool, bool,
bool, bool)
../../trunk/gcc/fortran/trans-expr.cc:11706
0xbad914 gfc_trans_assignment_1
../../trunk/gcc/fortran/trans-expr.cc:13423
0xb4ff77 trans_code
../../trunk/gcc/fortran/trans.cc:2349
0xb89741 gfc_generate_function_code(gfc_namespace*)
../../trunk/gcc/fortran/trans-decl.cc:8132
0xb55831 gfc_generate_module_code(gfc_namespace*)
../../trunk/gcc/fortran/trans.cc:2776
0xaefae5 translate_all_program_units
../../trunk/gcc/fortran/parse.cc:7515
0xaefae5 gfc_parse_file()
../../trunk/gcc/fortran/parse.cc:7848
0xb4c983 gfc_be_parse_file
../../trunk/gcc/fortran/f95-lang.cc:247
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
$ gfortran --version
GNU Fortran (GCC) 16.0.0 20251027 (experimental)
-----
flang 22.0.0git (a recent build of llvm-project's main branch) gives
./reproducer.f90:26:13: portability: Reference to generic function 'tensor_t'
(resolving to specific 'construct_double_precision') is ambiguous with a
structure constructor of the same name [-Wambiguous-structure-constructor]
const = tensor_t([0D0])
^^^^^^^^^^^^^^^
which I believe is incorrect because the structure constructor is unavailable
due to the tensor_t type having a private component.