* [PATCH v2] c++: Allow module name to be a single letter on Windows
@ 2022-11-02 16:03 Torbjörn SVENSSON
0 siblings, 0 replies; only message in thread
From: Torbjörn SVENSSON @ 2022-11-02 16:03 UTC (permalink / raw)
To: gcc-patches; +Cc: nathan, yvan.roux, Torbjörn SVENSSON
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 <yvan.roux@foss.st.com>
Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
---
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-11-02 16:04 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-02 16:03 [PATCH v2] c++: Allow module name to be a single letter on Windows Torbjörn SVENSSON
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).