Dear all, the attached patch prints the fully qualified path if an error occurs during module read. E.g., instead of a less helpful error message,
pr81651.f90:2:6: 2 | use netcdf | 1 Fatal Error: File 'netcdf.mod' opened at (1) is not a GNU Fortran module file gfortran will print pr81651.f90:2:7: 2 | use netcdf | 1 Fatal Error: File '/opt/pgi/pkg/netcdf/include/netcdf.mod' opened at (1) is not a GNU Fortran module file Regtested on x86_64-pc-linux-gnu. I couldn't think of a sensible test for the testsuite, thus no testcase provided. OK for trunk? Thanks, Harald 2019-11-11 Harald Anlauf <anl...@gmx.de> PR fortran/81651 * module.c (gzopen_included_file, gzopen_included_file_1) (gzopen_intrinsic_module, bad_module, gfc_use_module): Use fully qualified module path for error reporting.
Index: gcc/fortran/module.c =================================================================== --- gcc/fortran/module.c (revision 278064) +++ gcc/fortran/module.c (working copy) @@ -187,6 +187,8 @@ /* The gzFile for the module we're reading or writing. */ static gzFile module_fp; +/* Fully qualified module path */ +static char *module_fullpath = NULL; /* The name of the module we're reading (USE'ing) or writing. */ static const char *module_name; @@ -1101,6 +1103,8 @@ if (gfc_cpp_makedep ()) gfc_cpp_add_dep (fullname, system); + free (module_fullpath); + module_fullpath = xstrdup (fullname); return f; } } @@ -1116,8 +1120,14 @@ if (IS_ABSOLUTE_PATH (name) || include_cwd) { f = gzopen (name, "r"); - if (f && gfc_cpp_makedep ()) - gfc_cpp_add_dep (name, false); + if (f) + { + if (gfc_cpp_makedep ()) + gfc_cpp_add_dep (name, false); + + free (module_fullpath); + module_fullpath = xstrdup (name); + } } if (!f) @@ -1134,8 +1144,14 @@ if (IS_ABSOLUTE_PATH (name)) { f = gzopen (name, "r"); - if (f && gfc_cpp_makedep ()) - gfc_cpp_add_dep (name, true); + if (f) + { + if (gfc_cpp_makedep ()) + gfc_cpp_add_dep (name, true); + + free (module_fullpath); + module_fullpath = xstrdup (name); + } } if (!f) @@ -1181,7 +1197,7 @@ { case IO_INPUT: gfc_fatal_error ("Reading module %qs at line %d column %d: %s", - module_name, module_line, module_column, msgid); + module_fullpath, module_line, module_column, msgid); break; case IO_OUTPUT: gfc_fatal_error ("Writing module %qs at line %d column %d: %s", @@ -7141,7 +7157,7 @@ if ((start == 1 && strcmp (atom_name, "GFORTRAN") != 0) || (start == 2 && strcmp (atom_name, " module") != 0)) gfc_fatal_error ("File %qs opened at %C is not a GNU Fortran" - " module file", filename); + " module file", module_fullpath); if (start == 3) { if (strcmp (atom_name, " version") != 0 @@ -7150,7 +7166,7 @@ || strcmp (atom_string, MOD_VERSION)) gfc_fatal_error ("Cannot read module file %qs opened at %C," " because it was created by a different" - " version of GNU Fortran", filename); + " version of GNU Fortran", module_fullpath); free (atom_string); }