On Wed, Jan 08, 2025 at 04:34:18PM +0100, Jakub Jelinek wrote:
> I'm testing for that instead:
> --- gcc/module.cc.jj  2025-01-08 15:23:54.511732946 +0100
> +++ gcc/module.cc     2025-01-08 16:32:14.963984426 +0100
> @@ -7122,9 +7122,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.  */

Here is the full patch, passes make -j32 -k check-gfortran
(but haven't bootstrapped it yet, just tested after patching stage3
and rebuilding it).

2025-01-08  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.

--- gcc/fortran/module.cc.jj    2025-01-08 10:05:39.308786981 +0100
+++ gcc/fortran/module.cc       2025-01-08 16:32:14.963984426 +0100
@@ -85,6 +85,8 @@ along with GCC; see the file COPYING3.
 /* 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);
--- gcc/fortran/iso-c-binding.def.jj    2025-01-02 11:47:31.894198887 +0100
+++ gcc/fortran/iso-c-binding.def       2025-01-08 10:09:12.454799919 +0100
@@ -17,7 +17,8 @@ along with GCC; see the file COPYING3.
 <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,
 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
 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
--- gcc/fortran/iso-fortran-env.def.jj  2025-01-02 11:47:32.137195494 +0100
+++ gcc/fortran/iso-fortran-env.def     2025-01-08 10:11:44.946667057 +0100
@@ -17,7 +17,8 @@ along with GCC; see the file COPYING3.
 <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,
 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_FA
               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
                    ? 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


        Jakub

Reply via email to