Fortran: Fix directory stat check for '.' [PR103560]
Commit Message
As reported in the PR103560. The patch is a slightly modified version
of the patch proposed by the bug reporter (with pseudonym?) Carlos Une.
The problem seems to be that 'stat ("./", ...)' fails with MinGW while
'stat (".", ...)' works. Besides, I think it makes sense to defer the
usage of '/' until needed - and I believe the error messages also make
more sense now.
Due to diagnostic changes in GCC 12, this pre-exising old issue was
exposed and shows up as bootstrap fail in GCC 12.
I intent to commit it later today (to GCC 12, only),
unless someone suggests a change.
Tobias
PS: I was briefly considering to use DIR_SEPARATOR (as defined in system.h),
but that one is '/' (while DIR_SEPARATOR_2 is '\\', if defined). Thus, it
does not seem to be worthwhile - especially as '/' needs to be converted to
"/" for strcat - or
fullname[strlen(path)] = DIR_SEPARATOR; fullname[strlen(path)+1]='\0';
has to be used.
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
Fortran: Fix directory stat check for '.' [PR103560]
MinGW does not like a call to 'stat' for './' via gfc_do_check_include_dir.
Solution: Only append '/' when concatenating the path with the filename.
gcc/fortran/ChangeLog:
PR fortran/103560
* scanner.cc (add_path_to_list): Don't append '/' to the
save include path.
(open_included_file): Use '/' in concatenating path + file name.
* module.cc (gzopen_included_file_1): Likewise.
gcc/testsuite/ChangeLog:
PR fortran/103560
* gfortran.dg/include_14.f90: Update dg-warning.
* gfortran.dg/include_17.f90: Likewise.
* gfortran.dg/include_18.f90: Likewise.
* gfortran.dg/include_6.f90: Update dg-*.
---
gcc/fortran/module.cc | 3 ++-
gcc/fortran/scanner.cc | 7 +++----
gcc/testsuite/gfortran.dg/include_14.f90 | 4 ++--
gcc/testsuite/gfortran.dg/include_17.f90 | 4 ++--
gcc/testsuite/gfortran.dg/include_18.f90 | 4 ++--
gcc/testsuite/gfortran.dg/include_6.f90 | 2 +-
6 files changed, 12 insertions(+), 12 deletions(-)
@@ -1095,8 +1095,9 @@ gzopen_included_file_1 (const char *name, gfc_directorylist *list,
if (module && !p->use_for_modules)
continue;
- fullname = (char *) alloca(strlen (p->path) + strlen (name) + 1);
+ fullname = (char *) alloca(strlen (p->path) + strlen (name) + 2);
strcpy (fullname, p->path);
+ strcat (fullname, "/");
strcat (fullname, name);
f = gzopen (fullname, "r");
@@ -409,9 +409,7 @@ add_path_to_list (gfc_directorylist **list, const char *path,
*list = dir;
dir->use_for_modules = use_for_modules;
dir->warn = warn;
- dir->path = XCNEWVEC (char, strlen (p) + 2);
- strcpy (dir->path, p);
- strcat (dir->path, "/"); /* make '/' last character */
+ dir->path = xstrdup (p);
}
/* defer_warn is set to true while parsing the commandline. */
@@ -476,8 +474,9 @@ open_included_file (const char *name, gfc_directorylist *list,
if (module && !p->use_for_modules)
continue;
- fullname = (char *) alloca(strlen (p->path) + strlen (name) + 1);
+ fullname = (char *) alloca(strlen (p->path) + strlen (name) + 2);
strcpy (fullname, p->path);
+ strcat (fullname, "/");
strcat (fullname, name);
f = gfc_open_file (fullname);
@@ -1,6 +1,6 @@
! { dg-additional-options "-cpp -idirafter /fdaf/ -I bar -J foo/bar" }
end
! default: warn for -I and -J but ignore other options.
-! { dg-warning "Nonexistent include directory 'bar/'" "" { target *-*-* } 0 }
-! { dg-warning "Nonexistent include directory 'foo/bar/'" "" { target *-*-* } 0 }
+! { dg-warning "Nonexistent include directory 'bar'" "" { target *-*-* } 0 }
+! { dg-warning "Nonexistent include directory 'foo/bar'" "" { target *-*-* } 0 }
@@ -1,6 +1,6 @@
! { dg-do compile }
! { dg-options "-I foo-bar -J foo/bar" }
end
-! { dg-warning "Nonexistent include directory 'foo-bar/'" "" { target *-*-* } 0 }
-! { dg-warning "Nonexistent include directory 'foo/bar/'" "" { target *-*-* } 0 }
+! { dg-warning "Nonexistent include directory 'foo-bar'" "" { target *-*-* } 0 }
+! { dg-warning "Nonexistent include directory 'foo/bar'" "" { target *-*-* } 0 }
@@ -1,5 +1,5 @@
! { dg-do compile }
! { dg-options "-I nothere -J neither/here -Wmissing-include-dirs" }
end
-! { dg-warning "Nonexistent include directory 'nothere/'" "" { target *-*-* } 0 }
-! { dg-warning "Nonexistent include directory 'neither/here/'" "" { target *-*-* } 0 }
+! { dg-warning "Nonexistent include directory 'nothere'" "" { target *-*-* } 0 }
+! { dg-warning "Nonexistent include directory 'neither/here'" "" { target *-*-* } 0 }
@@ -1,6 +1,6 @@
! { dg-do compile }
! { dg-options "-I gfortran.log" }
-! { dg-warning "Include directory 'gfortran.log/': Not a directory" "" { target *-*-* } 0 }
+! { dg-error "'gfortran.log' is not a directory" "" { target *-*-* } 0 }
! { dg-prune-output "compilation terminated." }
end
--
2.25.1