https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122046
Bug ID: 122046
Summary: [14/15/16 Regression] ICE in is_illegal_recursion when
a TBP is used to specify the bounds of a dummy
argument
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: trnka at scm dot com
Target Milestone: ---
Created attachment 62441
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=62441&action=edit
testcase demonstrating the bug
Since GCC 14, gfortran crashes when compiling the attached testcase with the
following backtrace:
f951: internal compiler error: in is_illegal_recursion, at
fortran/resolve.cc:1843
0x404242 is_illegal_recursion
/home/tootea/gcc/src/gcc/fortran/resolve.cc:1843
0x404242 is_illegal_recursion
/home/tootea/gcc/src/gcc/fortran/resolve.cc:1789
0x701b7c resolve_function
/home/tootea/gcc/src/gcc/fortran/resolve.cc:3478
0x701b7c gfc_resolve_expr(gfc_expr*)
/home/tootea/gcc/src/gcc/fortran/resolve.cc:7498
0x70099c resolve_typebound_function
/home/tootea/gcc/src/gcc/fortran/resolve.cc:7158
0x70099c gfc_resolve_expr(gfc_expr*)
/home/tootea/gcc/src/gcc/fortran/resolve.cc:7509
0x63a296 resolve_array_bound
/home/tootea/gcc/src/gcc/fortran/array.cc:385
0x63b5e0 gfc_resolve_array_spec(gfc_array_spec*, int)
/home/tootea/gcc/src/gcc/fortran/array.cc:429
0x708a4f gfc_resolve_formal_arglist(gfc_symbol*)
/home/tootea/gcc/src/gcc/fortran/resolve.cc:334
0x729b12 do_traverse_symtree
/home/tootea/gcc/src/gcc/fortran/symbol.cc:4295
0x70928a resolve_formal_arglists
/home/tootea/gcc/src/gcc/fortran/resolve.cc:557
0x70928a resolve_contained_functions
/home/tootea/gcc/src/gcc/fortran/resolve.cc:1177
0x70928a resolve_types
/home/tootea/gcc/src/gcc/fortran/resolve.cc:18296
0x70f6fc gfc_resolve(gfc_namespace*)
/home/tootea/gcc/src/gcc/fortran/resolve.cc:18427
0x6ebc2c gfc_parse_file()
/home/tootea/gcc/src/gcc/fortran/parse.cc:7236
0x74376f gfc_be_parse_file
/home/tootea/gcc/src/gcc/fortran/f95-lang.cc:241
This is triggered by using a type-bound function of one dummy argument to
specify the array bounds of another dummy argument:
type(ChemicalSystemType), intent(in) :: modelSys
real , intent(out) :: rmsdGrad(3,modelSys%NumAtoms())
The bug bisects to the following commit (in 14.0 and newer):
commit 44c0398e65347def316700911a51ca8b4ec0a411
Author: Mikael Morin <[email protected]>
Date: Fri Mar 22 12:32:34 2024 +0100
fortran: Fix specification expression error with dummy procedures
[PR111781]
I suspect this paragraph from the commit message could be relevant:
Regarding the second bug, the problematic condition is removed, together
with the formal_arg_flag associated with it. Indeed, that condition was
(wrongly) allowing local variables to be used in array bounds of dummy
arguments.
Curiously enough, the ICE only occurs when the affected subroutine is defined
in a submodule. Moving the definition to the parent module makes the testcase
compile.
By my reading of the Fortran 2018 standard, the testcase should be legal
Fortran. The definition of specification expressions (10.1.11) used for
explicit-shape array bounds allows:
> (12) a reference to a specification function where each argument is a
> restricted
> expression,
where:
> A function is a specification function if it is a pure function, is not a
> standard
> intrinsic function, is not an internal function, is not a statement function,
> and
> does not have a dummy procedure argument.
All of these requirements appear to be satisfied by the TBP in the testcase.