From patchwork Thu Nov 17 13:20:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Torbjorn SVENSSON X-Patchwork-Id: 21666 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp402364wrr; Thu, 17 Nov 2022 05:36:30 -0800 (PST) X-Google-Smtp-Source: AA0mqf6g65mHa/QvX7Z1vnoa6+HEMP39El9vG3encH67+V4lo83WJQugFKIwYHKpU/XkJNRp0hQC X-Received: by 2002:a17:906:1e4a:b0:78d:3505:6f3e with SMTP id i10-20020a1709061e4a00b0078d35056f3emr2061043ejj.611.1668692190113; Thu, 17 Nov 2022 05:36:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668692190; cv=none; d=google.com; s=arc-20160816; b=DlAzMJghnbwJdUXWTYyxwtTEZXUbjrZuEoOciAnkJAL/mz1yzUJkxBDNmzUQ0UdyXY zBsTGvUXvzMT/VionpzThFpmQvaEe+Yu3elb7FmwGb2N2LKCni0b3mysuvM47cuWwKli rU9H32CddIXALeuRaGMNGBGgkP0Mmnnx0Ofr8Pw3vojUAVwsiXR1YCBsh4Bul3JPAYEM 0xLnJTw4tnk9XVKI7hoa0fw0OlFKbS4lozLq97MU7C81tO1UHCey7chxYztR5YSaHF5f bvKtpEEdng7os8LCRUp7c+8F7oDR5uZyYgwOmUrZMzZHhaHOgGejZuenB+jCFIvW14nw BThw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=p7G6h+J3DFyegdFD1b5tyxCdMPrD/oRyHClYd3+JP7s=; b=SJ4RoVC91bAs9R46/lOzH5EFerapa8Srgg52lZYMJP55EdDcwRRNNCL1WIEg0ok3qh rCi4tuZJ658hajrgDJpPOiIiDCldYyroT3wTLW5sjEX/+YShlu1M9tH13xYYWKvlhxtk vrED+jPd3C3LMdfPphcCYSiPl+cF24ciArhN0Mp1/FBxrVKnD6T9gjXBpFCFrlKcf217 hffoaV3OAW9Bl2D6/XAqqGCQPaL2QI9LkVjC5MqmfI8fANqzG+ZnCqJ1izYBOpWifKp+ wM6s4aZrV5LAIi4zCcLXab7QVxVQhez0ZbCv0Mx9pXwovw+ENL59qfpGp3HGy8ur3aEf ri3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=nzXMo39U; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id k9-20020a17090646c900b00774195db4e7si548388ejs.117.2022.11.17.05.36.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Nov 2022 05:36:30 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=nzXMo39U; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E5C3839960FA for ; Thu, 17 Nov 2022 13:36:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E5C3839960FA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668692188; bh=p7G6h+J3DFyegdFD1b5tyxCdMPrD/oRyHClYd3+JP7s=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=nzXMo39UkFksOduoMU0/nejVWxjqHqd6/tUvrP9p4KDe3euooSv14uaabHhvsssee YPkAWarEJPsiPdvYMzcT0CcL9CrC5Ub4rVGATFylgNVOPNCsudaRt9rq2R7LIGHWqr h7r0aRKpXfSlGoxcNr0FWJ1iMb0OyVh8vNxtAI7w= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [185.132.182.106]) by sourceware.org (Postfix) with ESMTPS id AFD8B39960EA for ; Thu, 17 Nov 2022 13:35:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AFD8B39960EA 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 2AHCAAHZ008980; Thu, 17 Nov 2022 14:35:15 +0100 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 3kwjvkthv6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 17 Nov 2022 14:35: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 BD218100034; Thu, 17 Nov 2022 14:35: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 A499A209319; Thu, 17 Nov 2022 14:35: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.2507.6; Thu, 17 Nov 2022 14:35:07 +0100 To: CC: , , =?utf-8?q?Torbj=C3=B6rn_SVENS?= =?utf-8?q?SON?= Subject: [PATCH v3] c++: Allow module name to be a single letter on Windows Date: Thu, 17 Nov 2022 14:20:22 +0100 Message-ID: <20221117132021.1143935-1-torbjorn.svensson@foss.st.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.210.54.218] X-ClientProxiedBy: EQNCAS1NODE3.st.com (10.75.129.80) To SHFDAG1NODE3.st.com (10.75.129.71) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-17_06,2022-11-17_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 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: , X-Patchwork-Original-From: =?utf-8?q?Torbj=C3=B6rn_SVENSSON_via_Gcc-patches?= From: Torbjorn SVENSSON Reply-To: =?utf-8?q?Torbj=C3=B6rn_SVENSSON?= Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749750581979544396?= X-GMAIL-MSGID: =?utf-8?q?1749750581979544396?= v1 -> v2: Paths without "C:" part can still be absolute if they start with / or \ on Windows. v2 -> v3: Use alternative approach by having platform specific code in module.cc. Truth table for the new expression: c:\foo -> true c:/foo -> true /foo -> true \foo -> true c:foo -> false foo -> false ./foo -> true .\foo -> true 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. gcc/cp/ChangeLog: * module.cc: On Windows, 'A:Foo' is supposed to be a module and not a path. 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 | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 0e9af318ba4..fa41a86213f 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -13960,7 +13960,15 @@ 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)) + /* On DOS based file systems, there is an ambiguity with A:B which can be + interpreted as a module Module:Partition or Drive:PATH. Interpret strings + which clearly starts as pathnames as header-names and everything else is + treated as a (possibly malformed) named moduled. */ + if (IS_DIR_SEPARATOR (ptr[ptr[0] == '.']) // ./FOO or /FOO +#if HAVE_DOS_BASED_FILE_SYSTEM + || (HAS_DRIVE_SPEC (ptr) && IS_DIR_SEPARATOR (ptr[2])) // A:/FOO +#endif + || false) /* A header name. */ return get_module (build_string (strlen (ptr), ptr));