From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [185.132.182.106]) by sourceware.org (Postfix) with ESMTPS id 193B83857351 for ; Wed, 2 Nov 2022 16:04:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 193B83857351 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=foss.st.com Received: from pps.filterd (m0288072.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2A2FNpMq030616; Wed, 2 Nov 2022 17:04:15 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : mime-version : content-type : content-transfer-encoding; s=selector1; bh=MqzneFSnCZ8xqMm6JpqXOBD1cz9uVrbY4PfU+g2w+WI=; b=Jr1qSC5IciLr9c2ILShlLWxec/EnAHEc1NYCvKQesGeiZYc9CEuhipOdJz8T3PbzcNph oKTmBpAEQi2/UsaoY3fxCJmAePlbV2jMGCI0NrAx2u2hfEau1p5xEdcoprlbM1uaG4Vg oK5h6OHGaDTbmHwI1fw77Acp798pVNS0SsY3XOH4kBoMvz2wuYaYCLHhMwNPqNflHvmr 2LkQQ1xkY6G86hYkOalXiXgtXOOlO8MGSwgFbSWn/4Op2WgvUNW7ARG6v9TN+324AbzU iELZVlwW+JhLV0NE2jl1J3Sift+r9wCn+Dx9PbaV25YQ8RvC4FHmAw2ZD+gC+2UjdYGS 9Q== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3kkqjcsqe7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 02 Nov 2022 17:04:15 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 273B2100034; Wed, 2 Nov 2022 17:04:10 +0100 (CET) Received: from Webmail-eu.st.com (shfdag1node3.st.com [10.75.129.71]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 16E2822F7D0; Wed, 2 Nov 2022 17:04:10 +0100 (CET) Received: from jkgcxl0002.jkg.st.com (10.210.54.218) by SHFDAG1NODE3.st.com (10.75.129.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 2 Nov 2022 17:04:09 +0100 From: =?UTF-8?q?Torbj=C3=B6rn=20SVENSSON?= To: CC: , , =?UTF-8?q?Torbj=C3=B6rn=20SVENSSON?= Subject: [PATCH v2] c++: Allow module name to be a single letter on Windows Date: Wed, 2 Nov 2022 17:03:09 +0100 Message-ID: <20221102160308.3675197-1-torbjorn.svensson@foss.st.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.210.54.218] X-ClientProxiedBy: SHFCAS1NODE2.st.com (10.75.129.73) To SHFDAG1NODE3.st.com (10.75.129.71) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-02_13,2022-11-02_01,2022-06-22_01 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: v1 -> v2: Paths without "C:" part can still be absolute if they start with / or \ on Windows. Ok for trunk? ----- On Windows, the ':' character is special and when the module name is a single character, like 'A', then the flatname would be (for example) 'A:Foo'. On Windows, 'A:Foo' is treated as an absolute path by the module loader and is likely not found. Without this patch, the test case pr98944_c.C fails with: In module imported at /src/gcc/testsuite/g++.dg/modules/pr98944_b.C:7:1, of module A:Foo, imported at /src/gcc/testsuite/g++.dg/modules/pr98944_c.C:7: A:Internals: error: header module expected, module 'A:Internals' found A:Internals: error: failed to read compiled module: Bad file data A:Internals: note: compiled module file is 'gcm.cache/A-Internals.gcm' In module imported at /src/gcc/testsuite/g++.dg/modules/pr98944_c.C:7:8: A:Foo: error: failed to read compiled module: Bad import dependency A:Foo: note: compiled module file is 'gcm.cache/A-Foo.gcm' A:Foo: fatal error: returning to the gate for a mechanical issue compilation terminated. include/ChangeLog: * filenames.h: Added IS_REAL_ABSOLUTE_PATH macro to check if path is absolute and not semi-absolute on Windows. gcc/cp/ChangeLog: * module.cc: Use IS_REAL_ABSOLUTE_PATH macro. Tested on Windows with arm-none-eabi for Cortex-M3 in gcc-11 tree. Co-Authored-By: Yvan ROUX Signed-off-by: Torbjörn SVENSSON --- gcc/cp/module.cc | 2 +- include/filenames.h | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 9957df510e6..84680e183b7 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -13958,7 +13958,7 @@ get_module (tree name, module_state *parent, bool partition) static module_state * get_module (const char *ptr) { - if (ptr[0] == '.' ? IS_DIR_SEPARATOR (ptr[1]) : IS_ABSOLUTE_PATH (ptr)) + if (ptr[0] == '.' ? IS_DIR_SEPARATOR (ptr[1]) : IS_REAL_ABSOLUTE_PATH (ptr)) /* A header name. */ return get_module (build_string (strlen (ptr), ptr)); diff --git a/include/filenames.h b/include/filenames.h index 6c72c422edd..5e08033ff36 100644 --- a/include/filenames.h +++ b/include/filenames.h @@ -43,6 +43,7 @@ extern "C" { # define HAS_DRIVE_SPEC(f) HAS_DOS_DRIVE_SPEC (f) # define IS_DIR_SEPARATOR(c) IS_DOS_DIR_SEPARATOR (c) # define IS_ABSOLUTE_PATH(f) IS_DOS_ABSOLUTE_PATH (f) +# define IS_REAL_ABSOLUTE_PATH(f) IS_DOS_REAL_ABSOLUTE_PATH (f) #else /* not DOSish */ # if defined(__APPLE__) # ifndef HAVE_CASE_INSENSITIVE_FILE_SYSTEM @@ -52,6 +53,7 @@ extern "C" { # define HAS_DRIVE_SPEC(f) (0) # define IS_DIR_SEPARATOR(c) IS_UNIX_DIR_SEPARATOR (c) # define IS_ABSOLUTE_PATH(f) IS_UNIX_ABSOLUTE_PATH (f) +# define IS_REAL_ABSOLUTE_PATH(f) IS_ABSOLUTE_PATH (f) #endif #define IS_DIR_SEPARATOR_1(dos_based, c) \ @@ -67,6 +69,7 @@ extern "C" { #define IS_DOS_DIR_SEPARATOR(c) IS_DIR_SEPARATOR_1 (1, c) #define IS_DOS_ABSOLUTE_PATH(f) IS_ABSOLUTE_PATH_1 (1, f) +#define IS_DOS_REAL_ABSOLUTE_PATH(f) IS_ABSOLUTE_PATH_2 (1, f) #define HAS_DOS_DRIVE_SPEC(f) HAS_DRIVE_SPEC_1 (1, f) #define IS_UNIX_DIR_SEPARATOR(c) IS_DIR_SEPARATOR_1 (0, c) @@ -81,6 +84,13 @@ extern "C" { (IS_DIR_SEPARATOR_1 (dos_based, (f)[0]) \ || HAS_DRIVE_SPEC_1 (dos_based, f)) +/* Identical to IS_ABSOLUTE_PATH_1, but do not allow semi-absolute paths + when DOS_BASED is true. */ +#define IS_ABSOLUTE_PATH_2(dos_based, f) \ + (IS_DIR_SEPARATOR_1 (dos_based, (f)[0]) \ + || (HAS_DRIVE_SPEC_1 (dos_based, f) \ + && IS_DIR_SEPARATOR_1 (dos_based, (f)[2]))) + extern int filename_cmp (const char *s1, const char *s2); #define FILENAME_CMP(s1, s2) filename_cmp(s1, s2) -- 2.25.1