https://gcc.gnu.org/g:c5e71d22d632889860ef079d4b0bff21eef8a660
commit r15-6724-gc5e71d22d632889860ef079d4b0bff21eef8a660 Author: Jakub Jelinek <ja...@redhat.com> Date: Thu Jan 9 08:25:49 2025 +0100 fortran: Accept "15" modules for compatibility [PR118337] Based on the comments in the PR, I've tried to write a patch which would try to keep backwards compatibility with the GCC 11-14 *.mod files. This means reordering the *.def files, so that the entries present already in GCC 11-14 come before the ones new in GCC 15, and tweaking modules.cc such that it can accept that ordering and while it has a newer MOD_VERSION, it accepts even the previous one when loading modules. 2025-01-09 Jakub Jelinek <ja...@redhat.com> PR fortran/118337 * module.cc (COMPAT_MOD_VERSIONS): Define. (use_iso_fortran_env_module): Don't assume all NAMED_INTCSTs come first followed by NAMED_UINTCSTs. (gfc_use_module): Accept also COMPAT_MOD_VERSIONS for compatibility. * iso-c-binding.def: Reorder entries so that the GCC 14 ones come before the ones new in GCC 15. * iso-fortran-env.def: Likewise. Diff: --- gcc/fortran/iso-c-binding.def | 115 ++++++++++++++++++++-------------------- gcc/fortran/iso-fortran-env.def | 42 ++++++++------- gcc/fortran/module.cc | 25 +++++++-- 3 files changed, 102 insertions(+), 80 deletions(-) diff --git a/gcc/fortran/iso-c-binding.def b/gcc/fortran/iso-c-binding.def index 14239cb849e1..a9159d24302c 100644 --- a/gcc/fortran/iso-c-binding.def +++ b/gcc/fortran/iso-c-binding.def @@ -17,7 +17,8 @@ along with GCC; see the file COPYING3. If not see <http://www.gnu.org/licenses/>. */ /* This file contains the definition of the types provided by the - Fortran 2003 ISO_C_BINDING intrinsic module. */ + Fortran 2003 ISO_C_BINDING intrinsic module. The ordering of + the entries matters for the *.mod backwards compatibility. */ #ifndef NAMED_INTCST # define NAMED_INTCST(a,b,c,d) @@ -112,62 +113,6 @@ NAMED_INTCST (ISOCBINDING_INT_FAST64_T, "c_int_fast64_t", \ NAMED_INTCST (ISOCBINDING_INT_FAST128_T, "c_int_fast128_t", get_int_kind_from_width (128), GFC_STD_GNU) -/* UNSIGNED. */ -NAMED_UINTCST (ISOCBINDING_UINT, "c_unsigned", gfc_c_uint_kind, \ - GFC_STD_UNSIGNED) -NAMED_UINTCST (ISOCBINDING_USHORT, "c_unsigned_short", \ - get_unsigned_kind_from_node (short_unsigned_type_node), \ - GFC_STD_UNSIGNED) -NAMED_UINTCST (ISOCBINDING_UCHAR, "c_unsigned_char", \ - get_unsigned_kind_from_node (unsigned_char_type_node), \ - GFC_STD_UNSIGNED) -NAMED_UINTCST (ISOCBINDING_ULONG, "c_unsigned_long", \ - get_unsigned_kind_from_node (long_unsigned_type_node), \ - GFC_STD_UNSIGNED) -NAMED_UINTCST (ISOCBINDING_ULONGLONG, "c_unsigned_long_long", \ - get_unsigned_kind_from_node (long_long_unsigned_type_node), \ - GFC_STD_UNSIGNED) -NAMED_UINTCST (ISOCBINDING_UINTMAX_T, "c_uintmax_t", \ - get_uint_kind_from_name (UINTMAX_TYPE), GFC_STD_UNSIGNED) -NAMED_UINTCST (ISOCBINDING_UINT8_T, "c_uint8_t", \ - get_uint_kind_from_name (UINT8_TYPE), GFC_STD_UNSIGNED) -NAMED_UINTCST (ISOCBINDING_UINT16_T, "c_uint16_t", \ - get_uint_kind_from_name (UINT16_TYPE), GFC_STD_UNSIGNED) -NAMED_UINTCST (ISOCBINDING_UINT32_T, "c_uint32_t", \ - get_uint_kind_from_name (UINT32_TYPE), GFC_STD_UNSIGNED) -NAMED_UINTCST (ISOCBINDING_UINT64_T, "c_uint64_t", \ - get_uint_kind_from_name (UINT64_TYPE), GFC_STD_UNSIGNED) -NAMED_UINTCST (ISOCBINDING_UINT128_T, "c_uint128_t", \ - get_uint_kind_from_width (128), GFC_STD_UNSIGNED) -NAMED_UINTCST (ISOCBINDING_UINT_LEAST8_T, "c_uint_least8_t", \ - get_uint_kind_from_name (UINT_LEAST8_TYPE), \ - GFC_STD_UNSIGNED) -NAMED_UINTCST (ISOCBINDING_UINT_LEAST16_T, "c_uint_least16_t", \ - get_uint_kind_from_name (UINT_LEAST16_TYPE), \ - GFC_STD_UNSIGNED) -NAMED_UINTCST (ISOCBINDING_UINT_LEAST32_T, "c_uint_least32_t", \ - get_uint_kind_from_name (UINT_LEAST32_TYPE),\ - GFC_STD_UNSIGNED) -NAMED_UINTCST (ISOCBINDING_UINT_LEAST64_T, "c_uint_least64_t", \ - get_uint_kind_from_name (UINT_LEAST64_TYPE),\ - GFC_STD_UNSIGNED) -NAMED_UINTCST (ISOCBINDING_UINT_LEAST128_T, "c_uint_least128_t", \ - get_uint_kind_from_width (128), GFC_STD_UNSIGNED) -NAMED_UINTCST (ISOCBINDING_UINT_FAST8_T, "c_uint_fast8_t", \ - get_uint_kind_from_name (UINT_FAST8_TYPE), \ - GFC_STD_UNSIGNED) -NAMED_UINTCST (ISOCBINDING_UINT_FAST16_T, "c_uint_fast16_t", \ - get_uint_kind_from_name (UINT_FAST16_TYPE), \ - GFC_STD_UNSIGNED) -NAMED_UINTCST (ISOCBINDING_UINT_FAST32_T, "c_uint_fast32_t", \ - get_uint_kind_from_name (UINT_FAST32_TYPE),\ - GFC_STD_UNSIGNED) -NAMED_UINTCST (ISOCBINDING_UINT_FAST64_T, "c_uint_fast64_t", \ - get_uint_kind_from_name (UINT_FAST64_TYPE),\ - GFC_STD_UNSIGNED) -NAMED_UINTCST (ISOCBINDING_UINT_FAST128_T, "c_uint_fast128_t", \ - get_uint_kind_from_width (128), GFC_STD_UNSIGNED) - NAMED_REALCST (ISOCBINDING_FLOAT, "c_float", \ get_real_kind_from_node (float_type_node), GFC_STD_F2003) NAMED_REALCST (ISOCBINDING_DOUBLE, "c_double", \ @@ -259,6 +204,62 @@ NAMED_FUNCTION (ISOCBINDING_C_SIZEOF, "c_sizeof", \ NAMED_FUNCTION (ISOCBINDING_F_C_STRING, "f_c_string", \ GFC_ISYM_F_C_STRING, GFC_STD_F2023) +/* UNSIGNED. */ +NAMED_UINTCST (ISOCBINDING_UINT, "c_unsigned", gfc_c_uint_kind, \ + GFC_STD_UNSIGNED) +NAMED_UINTCST (ISOCBINDING_USHORT, "c_unsigned_short", \ + get_unsigned_kind_from_node (short_unsigned_type_node), \ + GFC_STD_UNSIGNED) +NAMED_UINTCST (ISOCBINDING_UCHAR, "c_unsigned_char", \ + get_unsigned_kind_from_node (unsigned_char_type_node), \ + GFC_STD_UNSIGNED) +NAMED_UINTCST (ISOCBINDING_ULONG, "c_unsigned_long", \ + get_unsigned_kind_from_node (long_unsigned_type_node), \ + GFC_STD_UNSIGNED) +NAMED_UINTCST (ISOCBINDING_ULONGLONG, "c_unsigned_long_long", \ + get_unsigned_kind_from_node (long_long_unsigned_type_node), \ + GFC_STD_UNSIGNED) +NAMED_UINTCST (ISOCBINDING_UINTMAX_T, "c_uintmax_t", \ + get_uint_kind_from_name (UINTMAX_TYPE), GFC_STD_UNSIGNED) +NAMED_UINTCST (ISOCBINDING_UINT8_T, "c_uint8_t", \ + get_uint_kind_from_name (UINT8_TYPE), GFC_STD_UNSIGNED) +NAMED_UINTCST (ISOCBINDING_UINT16_T, "c_uint16_t", \ + get_uint_kind_from_name (UINT16_TYPE), GFC_STD_UNSIGNED) +NAMED_UINTCST (ISOCBINDING_UINT32_T, "c_uint32_t", \ + get_uint_kind_from_name (UINT32_TYPE), GFC_STD_UNSIGNED) +NAMED_UINTCST (ISOCBINDING_UINT64_T, "c_uint64_t", \ + get_uint_kind_from_name (UINT64_TYPE), GFC_STD_UNSIGNED) +NAMED_UINTCST (ISOCBINDING_UINT128_T, "c_uint128_t", \ + get_uint_kind_from_width (128), GFC_STD_UNSIGNED) +NAMED_UINTCST (ISOCBINDING_UINT_LEAST8_T, "c_uint_least8_t", \ + get_uint_kind_from_name (UINT_LEAST8_TYPE), \ + GFC_STD_UNSIGNED) +NAMED_UINTCST (ISOCBINDING_UINT_LEAST16_T, "c_uint_least16_t", \ + get_uint_kind_from_name (UINT_LEAST16_TYPE), \ + GFC_STD_UNSIGNED) +NAMED_UINTCST (ISOCBINDING_UINT_LEAST32_T, "c_uint_least32_t", \ + get_uint_kind_from_name (UINT_LEAST32_TYPE),\ + GFC_STD_UNSIGNED) +NAMED_UINTCST (ISOCBINDING_UINT_LEAST64_T, "c_uint_least64_t", \ + get_uint_kind_from_name (UINT_LEAST64_TYPE),\ + GFC_STD_UNSIGNED) +NAMED_UINTCST (ISOCBINDING_UINT_LEAST128_T, "c_uint_least128_t", \ + get_uint_kind_from_width (128), GFC_STD_UNSIGNED) +NAMED_UINTCST (ISOCBINDING_UINT_FAST8_T, "c_uint_fast8_t", \ + get_uint_kind_from_name (UINT_FAST8_TYPE), \ + GFC_STD_UNSIGNED) +NAMED_UINTCST (ISOCBINDING_UINT_FAST16_T, "c_uint_fast16_t", \ + get_uint_kind_from_name (UINT_FAST16_TYPE), \ + GFC_STD_UNSIGNED) +NAMED_UINTCST (ISOCBINDING_UINT_FAST32_T, "c_uint_fast32_t", \ + get_uint_kind_from_name (UINT_FAST32_TYPE),\ + GFC_STD_UNSIGNED) +NAMED_UINTCST (ISOCBINDING_UINT_FAST64_T, "c_uint_fast64_t", \ + get_uint_kind_from_name (UINT_FAST64_TYPE),\ + GFC_STD_UNSIGNED) +NAMED_UINTCST (ISOCBINDING_UINT_FAST128_T, "c_uint_fast128_t", \ + get_uint_kind_from_width (128), GFC_STD_UNSIGNED) + #undef NAMED_INTCST #undef NAMED_UINTCST #undef NAMED_REALCST diff --git a/gcc/fortran/iso-fortran-env.def b/gcc/fortran/iso-fortran-env.def index 3ecddb6c372d..b8926f4df93b 100644 --- a/gcc/fortran/iso-fortran-env.def +++ b/gcc/fortran/iso-fortran-env.def @@ -17,7 +17,8 @@ along with GCC; see the file COPYING3. If not see <http://www.gnu.org/licenses/>. */ /* This file contains the definition of the named integer constants provided - by the Fortran 2003 ISO_FORTRAN_ENV intrinsic module. */ + by the Fortran 2003 ISO_FORTRAN_ENV intrinsic module. The ordering of + the entries matters for the *.mod backwards compatibility. */ #ifndef NAMED_INTCST # define NAMED_INTCST(a,b,c,d) @@ -72,20 +73,10 @@ NAMED_INTCST (ISOFORTRANENV_IOSTAT_EOR, "iostat_eor", LIBERROR_EOR, \ NAMED_INTCST (ISOFORTRANENV_IOSTAT_INQUIRE_INTERNAL_UNIT, \ "iostat_inquire_internal_unit", LIBERROR_INQUIRE_INTERNAL_UNIT, \ GFC_STD_F2008) -NAMED_INTCST (ISOFORTRANENV_LOGICAL8, "logical8", \ - gfc_get_int_kind_from_width_isofortranenv (8), GFC_STD_F2023) -NAMED_INTCST (ISOFORTRANENV_LOGICAL16, "logical16", \ - gfc_get_int_kind_from_width_isofortranenv (16), GFC_STD_F2023) -NAMED_INTCST (ISOFORTRANENV_LOGICAL32, "logical32", \ - gfc_get_int_kind_from_width_isofortranenv (32), GFC_STD_F2023) -NAMED_INTCST (ISOFORTRANENV_LOGICAL64, "logical64", \ - gfc_get_int_kind_from_width_isofortranenv (64), GFC_STD_F2023) NAMED_INTCST (ISOFORTRANENV_NUMERIC_STORAGE_SIZE, "numeric_storage_size", \ gfc_numeric_storage_size, GFC_STD_F2003) NAMED_INTCST (ISOFORTRANENV_OUTPUT_UNIT, "output_unit", GFC_STDOUT_UNIT_NUMBER, \ GFC_STD_F2003) -NAMED_INTCST (ISOFORTRANENV_REAL16, "real16", \ - gfc_get_real_kind_from_width_isofortranenv (16), GFC_STD_F2023) NAMED_INTCST (ISOFORTRANENV_REAL32, "real32", \ gfc_get_real_kind_from_width_isofortranenv (32), GFC_STD_F2008) NAMED_INTCST (ISOFORTRANENV_REAL64, "real64", \ @@ -103,14 +94,7 @@ NAMED_INTCST (ISOFORTRANENV_FILE_STAT_FAILED_IMAGE, "stat_failed_image", \ GFC_STAT_FAILED_IMAGE, GFC_STD_F2018) NAMED_INTCST (ISOFORTRANENV_FILE_STAT_UNLOCKED, "stat_unlocked", \ GFC_STAT_UNLOCKED, GFC_STD_F2008) -NAMED_UINTCST (ISOFORTRANENV_UINT8, "uint8", \ - gfc_get_uint_kind_from_width_isofortranenv (8), GFC_STD_UNSIGNED) -NAMED_UINTCST (ISOFORTRANENV_UINT16, "uint16", \ - gfc_get_uint_kind_from_width_isofortranenv (16), GFC_STD_UNSIGNED) -NAMED_UINTCST (ISOFORTRANENV_UINT32, "uint32", \ - gfc_get_uint_kind_from_width_isofortranenv (32), GFC_STD_UNSIGNED) -NAMED_UINTCST (ISOFORTRANENV_UINT64, "uint64", \ - gfc_get_uint_kind_from_width_isofortranenv (64), GFC_STD_UNSIGNED) + /* The arguments to NAMED_KINDARRAY are: -- an internal name @@ -154,6 +138,26 @@ NAMED_DERIVED_TYPE (ISOFORTRAN_TEAM_TYPE, "team_type", \ ? get_int_kind_from_node (ptr_type_node) : gfc_default_integer_kind, GFC_STD_F2018) +NAMED_INTCST (ISOFORTRANENV_LOGICAL8, "logical8", \ + gfc_get_int_kind_from_width_isofortranenv (8), GFC_STD_F2023) +NAMED_INTCST (ISOFORTRANENV_LOGICAL16, "logical16", \ + gfc_get_int_kind_from_width_isofortranenv (16), GFC_STD_F2023) +NAMED_INTCST (ISOFORTRANENV_LOGICAL32, "logical32", \ + gfc_get_int_kind_from_width_isofortranenv (32), GFC_STD_F2023) +NAMED_INTCST (ISOFORTRANENV_LOGICAL64, "logical64", \ + gfc_get_int_kind_from_width_isofortranenv (64), GFC_STD_F2023) +NAMED_INTCST (ISOFORTRANENV_REAL16, "real16", \ + gfc_get_real_kind_from_width_isofortranenv (16), GFC_STD_F2023) + +NAMED_UINTCST (ISOFORTRANENV_UINT8, "uint8", \ + gfc_get_uint_kind_from_width_isofortranenv (8), GFC_STD_UNSIGNED) +NAMED_UINTCST (ISOFORTRANENV_UINT16, "uint16", \ + gfc_get_uint_kind_from_width_isofortranenv (16), GFC_STD_UNSIGNED) +NAMED_UINTCST (ISOFORTRANENV_UINT32, "uint32", \ + gfc_get_uint_kind_from_width_isofortranenv (32), GFC_STD_UNSIGNED) +NAMED_UINTCST (ISOFORTRANENV_UINT64, "uint64", \ + gfc_get_uint_kind_from_width_isofortranenv (64), GFC_STD_UNSIGNED) + #undef NAMED_INTCST #undef NAMED_UINTCST #undef NAMED_KINDARRAY diff --git a/gcc/fortran/module.cc b/gcc/fortran/module.cc index a058a714805a..63d0cdbee9f7 100644 --- a/gcc/fortran/module.cc +++ b/gcc/fortran/module.cc @@ -85,6 +85,8 @@ along with GCC; see the file COPYING3. If not see /* Don't put any single quote (') in MOD_VERSION, if you want it to be recognized. */ #define MOD_VERSION "16" +/* Older mod versions we can still parse. */ +#define COMPAT_MOD_VERSIONS { "15" } /* Structure that describes a position within a module file. */ @@ -7122,9 +7124,11 @@ use_iso_fortran_env_module (void) i = 0; #define NAMED_INTCST(a,b,c,d) symbol[i++].value = c; -#include "iso-fortran-env.def" - #define NAMED_UINTCST(a,b,c,d) symbol[i++].value = c; +#define NAMED_KINDARRAY(a,b,c,d) i++; +#define NAMED_DERIVED_TYPE(a,b,c,d) i++; +#define NAMED_FUNCTION(a,b,c,d) i++; +#define NAMED_SUBROUTINE(a,b,c,d) i++; #include "iso-fortran-env.def" /* Generate the symbol for the module itself. */ @@ -7451,10 +7455,23 @@ gfc_use_module (gfc_use_list *module) " module file", module_fullpath); if (start == 3) { + bool fatal = false; if (strcmp (atom_name, " version") != 0 || module_char () != ' ' - || parse_atom () != ATOM_STRING - || strcmp (atom_string, MOD_VERSION)) + || parse_atom () != ATOM_STRING) + fatal = true; + else if (strcmp (atom_string, MOD_VERSION)) + { + static const char *compat_mod_versions[] = COMPAT_MOD_VERSIONS; + fatal = true; + for (unsigned i = 0; i < ARRAY_SIZE (compat_mod_versions); ++i) + if (!strcmp (atom_string, compat_mod_versions[i])) + { + fatal = false; + break; + } + } + if (fatal) gfc_fatal_error ("Cannot read module file %qs opened at %C," " because it was created by a different" " version of GNU Fortran", module_fullpath);