Affects versions down to at least r5 : $ cat z1.f90 program p class(*), allocatable :: x, y equivalence (x, y) end $ cat z2.f90 program p type t end type class(t), allocatable :: x, y equivalence (x, y) end $ cat z0.f90 # ok, allocatable object or pointer not allowed program p type t end type type(t), allocatable :: x, y equivalence (x, y) end $ gfortran-11-20200607 -c z1.f90 f951: internal compiler error: Invalid expression in gfc_target_encode_expr. 0x654af9 gfc_report_diagnostic ../../gcc/fortran/error.c:782 0x65621a gfc_internal_error(char const*, ...) ../../gcc/fortran/error.c:1402 0x6f3200 gfc_target_encode_expr(gfc_expr*, unsigned char*, unsigned long) ../../gcc/fortran/target-memory.c:362 0x6f32ff expr_to_char ../../gcc/fortran/target-memory.c:697 0x6f3dd0 gfc_merge_initializers(gfc_typespec, gfc_expr*, locus*, unsigned char*, unsigned char*, unsigned long) ../../gcc/fortran/target-memory.c:735 0x71cc63 get_init_field ../../gcc/fortran/trans-common.c:544 0x71cc63 create_common ../../gcc/fortran/trans-common.c:633 0x71e111 finish_equivalences ../../gcc/fortran/trans-common.c:1326 0x71e111 gfc_trans_common(gfc_namespace*) ../../gcc/fortran/trans-common.c:1363 0x72b60f gfc_generate_function_code(gfc_namespace*) ../../gcc/fortran/trans-decl.c:6764 0x6b3126 translate_all_program_units ../../gcc/fortran/parse.c:6306 0x6b3126 gfc_parse_file() ../../gcc/fortran/parse.c:6545 0x6feb3f gfc_be_parse_file ../../gcc/fortran/f95-lang.c:212
Confirmed.
The ICE is fixed by this patch: diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c index 82d2b5087e5..8063fcad295 100644 --- a/gcc/fortran/match.c +++ b/gcc/fortran/match.c @@ -5700,6 +5700,11 @@ gfc_match_equivalence (void) if (!gfc_add_in_equivalence (&sym->attr, sym->name, NULL)) goto cleanup; + if (sym->ts.type == BT_CLASS + && CLASS_DATA (sym) + && !gfc_add_in_equivalence (&CLASS_DATA (sym)->attr, + sym->name, NULL)) + goto cleanup; if (sym->attr.in_common) { Haven't tested this thoroughly yet.
Regtests cleanly. Submitted for review: https://gcc.gnu.org/pipermail/fortran/2020-June/054554.html
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>: https://gcc.gnu.org/g:5eb947601bdce59f2ff26694327ad173c51c2724 commit r11-1566-g5eb947601bdce59f2ff26694327ad173c51c2724 Author: Harald Anlauf <anlauf@gmx.de> Date: Sat Jun 20 16:05:13 2020 +0200 PR fortran/95587 - ICE in gfc_target_encode_expr, at fortran/target-memory.c:362 EQUIVALENCE objects are subject to constraints listed in the Fortran 2018 standard, section 8.10.1.1. These constraints are to be checked also for CLASS variables. gcc/fortran/ PR fortran/95587 * match.c (gfc_match_equivalence): Check constraints on EQUIVALENCE objects also for CLASS variables.
The releases/gcc-10 branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>: https://gcc.gnu.org/g:c00ca04ba7e46d2d59e5a4f95ee7121cdc4ba224 commit r10-8337-gc00ca04ba7e46d2d59e5a4f95ee7121cdc4ba224 Author: Harald Anlauf <anlauf@gmx.de> Date: Sat Jun 20 16:05:13 2020 +0200 PR fortran/95587 - ICE in gfc_target_encode_expr, at fortran/target-memory.c:362 EQUIVALENCE objects are subject to constraints listed in the Fortran 2018 standard, section 8.10.1.1. These constraints are to be checked also for CLASS variables. gcc/fortran/ PR fortran/95587 * match.c (gfc_match_equivalence): Check constraints on EQUIVALENCE objects also for CLASS variables. (cherry picked from commit 5eb947601bdce59f2ff26694327ad173c51c2724)
The releases/gcc-9 branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>: https://gcc.gnu.org/g:449246af10befa7e973cd6f864138e6cdd5c24e5 commit r9-8692-g449246af10befa7e973cd6f864138e6cdd5c24e5 Author: Harald Anlauf <anlauf@gmx.de> Date: Sat Jun 20 16:05:13 2020 +0200 PR fortran/95587 - ICE in gfc_target_encode_expr, at fortran/target-memory.c:362 EQUIVALENCE objects are subject to constraints listed in the Fortran 2018 standard, section 8.10.1.1. These constraints are to be checked also for CLASS variables. gcc/fortran/ PR fortran/95587 * match.c (gfc_match_equivalence): Check constraints on EQUIVALENCE objects also for CLASS variables. (cherry picked from commit 5eb947601bdce59f2ff26694327ad173c51c2724)
Fixed on master for GCC-11, and backported to 10-branch and 9-branch. Closing. Thanks for the report!