From patchwork Wed Mar 23 13:55:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 52254 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4EEB03945C1F for ; Wed, 23 Mar 2022 13:56:06 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa4.mentor.iphmx.com (esa4.mentor.iphmx.com [68.232.137.252]) by sourceware.org (Postfix) with ESMTPS id C3AC43858002; Wed, 23 Mar 2022 13:55:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C3AC43858002 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.90,204,1643702400"; d="scan'208";a="73491144" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 23 Mar 2022 05:55:17 -0800 IronPort-SDR: 71LGUNJ0VUAgBMycV4RMdAuQbP1p5LXxZIHqT09Nn9Nh5AFwoSvVTzrxiGEIwyTZYYVAM0Z9a5 Q4SPVHJIQa0FbfBlTofpVOEyu8zj713mm/9svvWU4RwvzjovDf2MqfNmlE5zGjsgaQBFKbk3qD UwyJqALahUY02sXwgy5+OVzluFZJ9hkTF7UkhKKkASEOZTR083BvyQNpnmxvIkVvwYMc6gIlom R56LhWa20iU+hBJZ/MrlTvPKF87Jlve1AdFSrDgUtS2a7+NF59BMCrIo+ltz614xLr3+0k70NW qVg= Message-ID: <44c4d042-ecaf-43cd-3461-66ae48eabd7a@codesourcery.com> Date: Wed, 23 Mar 2022 14:55:04 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Content-Language: en-US To: gcc-patches , fortran From: Tobias Burnus Subject: [PATCH] Fortran: Fix directory stat check for '.' [PR103560] X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-14.mgc.mentorg.com (139.181.222.14) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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(-) diff --git a/gcc/fortran/module.cc b/gcc/fortran/module.cc index 281b1b17fbf..85aa153bd77 100644 --- a/gcc/fortran/module.cc +++ b/gcc/fortran/module.cc @@ -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"); diff --git a/gcc/fortran/scanner.cc b/gcc/fortran/scanner.cc index b52282b687b..2dff2514700 100644 --- a/gcc/fortran/scanner.cc +++ b/gcc/fortran/scanner.cc @@ -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); diff --git a/gcc/testsuite/gfortran.dg/include_14.f90 b/gcc/testsuite/gfortran.dg/include_14.f90 index 8110e49bf43..39acf69b1b4 100644 --- a/gcc/testsuite/gfortran.dg/include_14.f90 +++ b/gcc/testsuite/gfortran.dg/include_14.f90 @@ -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 } diff --git a/gcc/testsuite/gfortran.dg/include_17.f90 b/gcc/testsuite/gfortran.dg/include_17.f90 index 06677590be3..f09b22f079a 100644 --- a/gcc/testsuite/gfortran.dg/include_17.f90 +++ b/gcc/testsuite/gfortran.dg/include_17.f90 @@ -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 } diff --git a/gcc/testsuite/gfortran.dg/include_18.f90 b/gcc/testsuite/gfortran.dg/include_18.f90 index b74a585bf1b..7ca0e48f091 100644 --- a/gcc/testsuite/gfortran.dg/include_18.f90 +++ b/gcc/testsuite/gfortran.dg/include_18.f90 @@ -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 } diff --git a/gcc/testsuite/gfortran.dg/include_6.f90 b/gcc/testsuite/gfortran.dg/include_6.f90 index 3e3be1b7bd5..2cea47390f4 100644 --- a/gcc/testsuite/gfortran.dg/include_6.f90 +++ b/gcc/testsuite/gfortran.dg/include_6.f90 @@ -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