public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: Allow module name to be a single letter on Windows
@ 2022-10-28  9:15 Torbjörn SVENSSON
  2022-11-03 14:17 ` Nathan Sidwell
  0 siblings, 1 reply; 6+ messages in thread
From: Torbjörn SVENSSON @ 2022-10-28  9:15 UTC (permalink / raw)
  To: gcc-patches; +Cc: nathan, yvan.roux, Torbjörn SVENSSON

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.

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 | 4 ++++
 2 files changed, 5 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..d04fccfed64 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,8 @@ 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) \
+  ((f)[0] && (f)[1] == ':' && ((f)[2] == '/' || (f)[2] == '\\'))
 #define HAS_DOS_DRIVE_SPEC(f) HAS_DRIVE_SPEC_1 (1, f)
 
 #define IS_UNIX_DIR_SEPARATOR(c) IS_DIR_SEPARATOR_1 (0, c)
-- 
2.25.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] c++: Allow module name to be a single letter on Windows
  2022-10-28  9:15 [PATCH] c++: Allow module name to be a single letter on Windows Torbjörn SVENSSON
@ 2022-11-03 14:17 ` Nathan Sidwell
  2022-11-03 15:06   ` Torbjorn SVENSSON
  0 siblings, 1 reply; 6+ messages in thread
From: Nathan Sidwell @ 2022-11-03 14:17 UTC (permalink / raw)
  To: Torbjörn SVENSSON, gcc-patches; +Cc: yvan.roux

On 10/28/22 05:15, Torbjörn SVENSSON wrote:
> 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.

Hm, this is unfortunate.  The current IS_ABSOLUTE_PATH, is really 'not relative 
to cwd', and even then that's untrue if the drive letter there is the drive 
letter of cwd, right?

It's awkward to have a new macro for just this purpose and the new name isn't 
very indicative of the difference to the current IS_ABSOLUTE_PATH.

Would it be better to not deal with drive letters here?  How prevalent are they 
these days in windows?  Would something like

    if (IS_DIR_SEPARATOR (ptr[ptr[0] == '.'])

suffice?

or, failing that perhaps put some explicit WINDOWS-specific #ifdef'd code there? 
  It's a real corner case.

nathan

> 
> gcc/cp/ChangeLog:
> 
> 	* module.cc: Use IS_REAL_ABSOLUTE_PATH macro.
> 
> 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 | 4 ++++
>   2 files changed, 5 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..d04fccfed64 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,8 @@ 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) \
> +  ((f)[0] && (f)[1] == ':' && ((f)[2] == '/' || (f)[2] == '\\'))
>   #define HAS_DOS_DRIVE_SPEC(f) HAS_DRIVE_SPEC_1 (1, f)
>   
>   #define IS_UNIX_DIR_SEPARATOR(c) IS_DIR_SEPARATOR_1 (0, c)

-- 
Nathan Sidwell


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] c++: Allow module name to be a single letter on Windows
  2022-11-03 14:17 ` Nathan Sidwell
@ 2022-11-03 15:06   ` Torbjorn SVENSSON
  2022-11-07 23:03     ` Nathan Sidwell
  0 siblings, 1 reply; 6+ messages in thread
From: Torbjorn SVENSSON @ 2022-11-03 15:06 UTC (permalink / raw)
  To: Nathan Sidwell, gcc-patches; +Cc: yvan.roux



On 2022-11-03 15:17, Nathan Sidwell wrote:
> On 10/28/22 05:15, Torbjörn SVENSSON wrote:
>> 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.
> 
> Hm, this is unfortunate.  The current IS_ABSOLUTE_PATH, is really 'not 
> relative to cwd', and even then that's untrue if the drive letter there 
> is the drive letter of cwd, right?
> 
> It's awkward to have a new macro for just this purpose and the new name 
> isn't very indicative of the difference to the current IS_ABSOLUTE_PATH.
> 
> Would it be better to not deal with drive letters here?  How prevalent 
> are they these days in windows?  Would something like
> 
>     if (IS_DIR_SEPARATOR (ptr[ptr[0] == '.'])
> 
> suffice?

I don't think you can ignore the drive letter part... see below.


#include <stdio.h>
#include "include/filenames.h"
#define TF(x) ((x) ? "true" : "false")
int main(int argc, char *argv[]) {
   const char *test[] = {
       /* absolute */      "c:\\foo", "c:/foo", "/foo", "\\foo",
       /* semi-absolute */ "c:foo",
       /* relative */      "foo", "./foo", ".\\foo",
   };
   for (int i = 0; i < sizeof(test) / sizeof(test[0]); i++) {
     const char *ptr = test[i];
     printf("\nptr: %s\n", ptr);
     printf("  IS_DOS_ABSOLUTE_PATH: %s\n",
            TF(IS_DOS_ABSOLUTE_PATH(ptr)));
     printf("  IS_DOS_REAL_ABSOLUTE_PATH: %s\n",
            TF(IS_DOS_REAL_ABSOLUTE_PATH(ptr)));
     printf("  IS_DIR_SEPARATOR: %s\n",
            TF(IS_DIR_SEPARATOR(ptr[ptr[0] == '.'])));
   }
   return 0;
}


The output is:

ptr: c:\foo
   IS_DOS_ABSOLUTE_PATH: true
   IS_DOS_REAL_ABSOLUTE_PATH: true
   IS_DIR_SEPARATOR: false

ptr: c:/foo
   IS_DOS_ABSOLUTE_PATH: true
   IS_DOS_REAL_ABSOLUTE_PATH: true
   IS_DIR_SEPARATOR: false

ptr: /foo
   IS_DOS_ABSOLUTE_PATH: true
   IS_DOS_REAL_ABSOLUTE_PATH: true
   IS_DIR_SEPARATOR: true

ptr: \foo
   IS_DOS_ABSOLUTE_PATH: true
   IS_DOS_REAL_ABSOLUTE_PATH: true
   IS_DIR_SEPARATOR: false

ptr: c:foo
   IS_DOS_ABSOLUTE_PATH: true
   IS_DOS_REAL_ABSOLUTE_PATH: false
   IS_DIR_SEPARATOR: false

ptr: foo
   IS_DOS_ABSOLUTE_PATH: false
   IS_DOS_REAL_ABSOLUTE_PATH: false
   IS_DIR_SEPARATOR: false

ptr: ./foo
   IS_DOS_ABSOLUTE_PATH: false
   IS_DOS_REAL_ABSOLUTE_PATH: false
   IS_DIR_SEPARATOR: true

ptr: .\foo
   IS_DOS_ABSOLUTE_PATH: false
   IS_DOS_REAL_ABSOLUTE_PATH: false
   IS_DIR_SEPARATOR: false


> 
> or, failing that perhaps put some explicit WINDOWS-specific #ifdef'd 
> code there?  It's a real corner case.

Would you rather have something like this in module.cc?

if (ptr[0] == '.')
   {
     if IS_DIR_SEPARATOR (ptr[1]))
       return get_module (build_string (strlen (ptr), ptr));
   }
else
   {
#if HAVE_DOS_BASED_FILE_SYSTEM
     if (HAS_DRIVE_SPEC (ptr) && IS_DIR_SEPARATOR (ptr[2]))
#else
     if (IS_ABSOLUTE_PATH (ptr))
#endif
       return get_module (build_string (strlen (ptr), ptr));
   }


Let me know what you prefer.

Kind regards,
Torbjörn

> 
> nathan
> 
>>
>> gcc/cp/ChangeLog:
>>
>>     * module.cc: Use IS_REAL_ABSOLUTE_PATH macro.
>>
>> 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 | 4 ++++
>>   2 files changed, 5 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..d04fccfed64 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,8 @@ 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) \
>> +  ((f)[0] && (f)[1] == ':' && ((f)[2] == '/' || (f)[2] == '\\'))
>>   #define HAS_DOS_DRIVE_SPEC(f) HAS_DRIVE_SPEC_1 (1, f)
>>   #define IS_UNIX_DIR_SEPARATOR(c) IS_DIR_SEPARATOR_1 (0, c)
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] c++: Allow module name to be a single letter on Windows
  2022-11-03 15:06   ` Torbjorn SVENSSON
@ 2022-11-07 23:03     ` Nathan Sidwell
  2022-11-08 10:18       ` Torbjorn SVENSSON
  0 siblings, 1 reply; 6+ messages in thread
From: Nathan Sidwell @ 2022-11-07 23:03 UTC (permalink / raw)
  To: Torbjorn SVENSSON, gcc-patches; +Cc: yvan.roux

On 11/3/22 11:06, Torbjorn SVENSSON wrote:
> 
> 
> On 2022-11-03 15:17, Nathan Sidwell wrote:
>> On 10/28/22 05:15, Torbjörn SVENSSON wrote:
>>> 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.
>>
>> Hm, this is unfortunate.  The current IS_ABSOLUTE_PATH, is really 'not 
>> relative to cwd', and even then that's untrue if the drive letter there is the 
>> drive letter of cwd, right?
>>
>> It's awkward to have a new macro for just this purpose and the new name isn't 
>> very indicative of the difference to the current IS_ABSOLUTE_PATH.
>>
>> Would it be better to not deal with drive letters here?  How prevalent are 
>> they these days in windows?  Would something like
>>
>>     if (IS_DIR_SEPARATOR (ptr[ptr[0] == '.'])
>>
>> suffice?
> 
> I don't think you can ignore the drive letter part... see below.
> 
> 
> #include <stdio.h>
> #include "include/filenames.h"
> #define TF(x) ((x) ? "true" : "false")
> int main(int argc, char *argv[]) {
>    const char *test[] = {
>        /* absolute */      "c:\\foo", "c:/foo", "/foo", "\\foo",
>        /* semi-absolute */ "c:foo",
>        /* relative */      "foo", "./foo", ".\\foo",
>    };
>    for (int i = 0; i < sizeof(test) / sizeof(test[0]); i++) {
>      const char *ptr = test[i];
>      printf("\nptr: %s\n", ptr);
>      printf("  IS_DOS_ABSOLUTE_PATH: %s\n",
>             TF(IS_DOS_ABSOLUTE_PATH(ptr)));
>      printf("  IS_DOS_REAL_ABSOLUTE_PATH: %s\n",
>             TF(IS_DOS_REAL_ABSOLUTE_PATH(ptr)));
>      printf("  IS_DIR_SEPARATOR: %s\n",
>             TF(IS_DIR_SEPARATOR(ptr[ptr[0] == '.'])));
>    }
>    return 0;
> }
> 
> 
> The output is:
> 
> ptr: c:\foo
>    IS_DOS_ABSOLUTE_PATH: true
>    IS_DOS_REAL_ABSOLUTE_PATH: true
>    IS_DIR_SEPARATOR: false
> 
> ptr: c:/foo
>    IS_DOS_ABSOLUTE_PATH: true
>    IS_DOS_REAL_ABSOLUTE_PATH: true
>    IS_DIR_SEPARATOR: false
> 
> ptr: /foo
>    IS_DOS_ABSOLUTE_PATH: true
>    IS_DOS_REAL_ABSOLUTE_PATH: true
>    IS_DIR_SEPARATOR: true
> 
> ptr: \foo
>    IS_DOS_ABSOLUTE_PATH: true
>    IS_DOS_REAL_ABSOLUTE_PATH: true
>    IS_DIR_SEPARATOR: false
> 
> ptr: c:foo
>    IS_DOS_ABSOLUTE_PATH: true
>    IS_DOS_REAL_ABSOLUTE_PATH: false
>    IS_DIR_SEPARATOR: false
> 
> ptr: foo
>    IS_DOS_ABSOLUTE_PATH: false
>    IS_DOS_REAL_ABSOLUTE_PATH: false
>    IS_DIR_SEPARATOR: false
> 
> ptr: ./foo
>    IS_DOS_ABSOLUTE_PATH: false
>    IS_DOS_REAL_ABSOLUTE_PATH: false
>    IS_DIR_SEPARATOR: true
> 
> ptr: .\foo
>    IS_DOS_ABSOLUTE_PATH: false
>    IS_DOS_REAL_ABSOLUTE_PATH: false
>    IS_DIR_SEPARATOR: false
> 
> 
>>
>> or, failing that perhaps put some explicit WINDOWS-specific #ifdef'd code 
>> there?  It's a real corner case.
> 
> Would you rather have something like this in module.cc?
> 
> if (ptr[0] == '.')
>    {
>      if IS_DIR_SEPARATOR (ptr[1]))
>        return get_module (build_string (strlen (ptr), ptr));
>    }
> else
>    {
> #if HAVE_DOS_BASED_FILE_SYSTEM
>      if (HAS_DRIVE_SPEC (ptr) && IS_DIR_SEPARATOR (ptr[2]))
> #else
>      if (IS_ABSOLUTE_PATH (ptr))
> #endif
>        return get_module (build_string (strlen (ptr), ptr));
>    }

Yes, something like the above, but I think you're missing "/bob' in the 
DOS_BASED case?  shouldn't that also be a pathname?

if (IS_DIR_SEPARATOR (ptr[ptr[0] == '.']) // ./FOO or /FOO
#if HAVE_DOS_BASED_FILE_SYSTEM
     // DOS-FS IS_ABSOLUTE_PATH thinks 'A:B' is absolute, but we need to consider
     // that as a module:partition.
     || (HAS_DRIVE_SPEC (ptr) && IS_DIR_SEPARATOR (ptr[2])) // A:/FOO
#endif
     || false)
    return ....

Does (something like) that work?

nathan

> 
> 
> Let me know what you prefer.
> 
> Kind regards,
> Torbjörn
> 
>>
>> nathan
>>
>>>
>>> gcc/cp/ChangeLog:
>>>
>>>     * module.cc: Use IS_REAL_ABSOLUTE_PATH macro.
>>>
>>> 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 | 4 ++++
>>>   2 files changed, 5 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..d04fccfed64 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,8 @@ 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) \
>>> +  ((f)[0] && (f)[1] == ':' && ((f)[2] == '/' || (f)[2] == '\\'))
>>>   #define HAS_DOS_DRIVE_SPEC(f) HAS_DRIVE_SPEC_1 (1, f)
>>>   #define IS_UNIX_DIR_SEPARATOR(c) IS_DIR_SEPARATOR_1 (0, c)
>>

-- 
Nathan Sidwell


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] c++: Allow module name to be a single letter on Windows
  2022-11-07 23:03     ` Nathan Sidwell
@ 2022-11-08 10:18       ` Torbjorn SVENSSON
  2022-11-08 12:10         ` Nathan Sidwell
  0 siblings, 1 reply; 6+ messages in thread
From: Torbjorn SVENSSON @ 2022-11-08 10:18 UTC (permalink / raw)
  To: Nathan Sidwell, gcc-patches; +Cc: yvan.roux

Hi Nathan,

On 2022-11-08 00:03, Nathan Sidwell wrote:
> On 11/3/22 11:06, Torbjorn SVENSSON wrote:
>>
>>
>> On 2022-11-03 15:17, Nathan Sidwell wrote:
>>> On 10/28/22 05:15, Torbjörn SVENSSON wrote:
>>>> 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.
>>>
>>> Hm, this is unfortunate.  The current IS_ABSOLUTE_PATH, is really 
>>> 'not relative to cwd', and even then that's untrue if the drive 
>>> letter there is the drive letter of cwd, right?
>>>
>>> It's awkward to have a new macro for just this purpose and the new 
>>> name isn't very indicative of the difference to the current 
>>> IS_ABSOLUTE_PATH.
>>>
>>> Would it be better to not deal with drive letters here?  How 
>>> prevalent are they these days in windows?  Would something like
>>>
>>>     if (IS_DIR_SEPARATOR (ptr[ptr[0] == '.'])
>>>
>>> suffice?
>>
>> I don't think you can ignore the drive letter part... see below.
>>
>>
>> #include <stdio.h>
>> #include "include/filenames.h"
>> #define TF(x) ((x) ? "true" : "false")
>> int main(int argc, char *argv[]) {
>>    const char *test[] = {
>>        /* absolute */      "c:\\foo", "c:/foo", "/foo", "\\foo",
>>        /* semi-absolute */ "c:foo",
>>        /* relative */      "foo", "./foo", ".\\foo",
>>    };
>>    for (int i = 0; i < sizeof(test) / sizeof(test[0]); i++) {
>>      const char *ptr = test[i];
>>      printf("\nptr: %s\n", ptr);
>>      printf("  IS_DOS_ABSOLUTE_PATH: %s\n",
>>             TF(IS_DOS_ABSOLUTE_PATH(ptr)));
>>      printf("  IS_DOS_REAL_ABSOLUTE_PATH: %s\n",
>>             TF(IS_DOS_REAL_ABSOLUTE_PATH(ptr)));
>>      printf("  IS_DIR_SEPARATOR: %s\n",
>>             TF(IS_DIR_SEPARATOR(ptr[ptr[0] == '.'])));
>>    }
>>    return 0;
>> }
>>
>>
>> The output is:
>>
>> ptr: c:\foo
>>    IS_DOS_ABSOLUTE_PATH: true
>>    IS_DOS_REAL_ABSOLUTE_PATH: true
>>    IS_DIR_SEPARATOR: false
>>
>> ptr: c:/foo
>>    IS_DOS_ABSOLUTE_PATH: true
>>    IS_DOS_REAL_ABSOLUTE_PATH: true
>>    IS_DIR_SEPARATOR: false
>>
>> ptr: /foo
>>    IS_DOS_ABSOLUTE_PATH: true
>>    IS_DOS_REAL_ABSOLUTE_PATH: true
>>    IS_DIR_SEPARATOR: true
>>
>> ptr: \foo
>>    IS_DOS_ABSOLUTE_PATH: true
>>    IS_DOS_REAL_ABSOLUTE_PATH: true
>>    IS_DIR_SEPARATOR: false
>>
>> ptr: c:foo
>>    IS_DOS_ABSOLUTE_PATH: true
>>    IS_DOS_REAL_ABSOLUTE_PATH: false
>>    IS_DIR_SEPARATOR: false
>>
>> ptr: foo
>>    IS_DOS_ABSOLUTE_PATH: false
>>    IS_DOS_REAL_ABSOLUTE_PATH: false
>>    IS_DIR_SEPARATOR: false
>>
>> ptr: ./foo
>>    IS_DOS_ABSOLUTE_PATH: false
>>    IS_DOS_REAL_ABSOLUTE_PATH: false
>>    IS_DIR_SEPARATOR: true
>>
>> ptr: .\foo
>>    IS_DOS_ABSOLUTE_PATH: false
>>    IS_DOS_REAL_ABSOLUTE_PATH: false
>>    IS_DIR_SEPARATOR: false
>>
>>
>>>
>>> or, failing that perhaps put some explicit WINDOWS-specific #ifdef'd 
>>> code there?  It's a real corner case.
>>
>> Would you rather have something like this in module.cc?
>>
>> if (ptr[0] == '.')
>>    {
>>      if IS_DIR_SEPARATOR (ptr[1]))
>>        return get_module (build_string (strlen (ptr), ptr));
>>    }
>> else
>>    {
>> #if HAVE_DOS_BASED_FILE_SYSTEM
>>      if (HAS_DRIVE_SPEC (ptr) && IS_DIR_SEPARATOR (ptr[2]))
>> #else
>>      if (IS_ABSOLUTE_PATH (ptr))
>> #endif
>>        return get_module (build_string (strlen (ptr), ptr));
>>    }
> 
> Yes, something like the above, but I think you're missing "/bob' in the 
> DOS_BASED case?  shouldn't that also be a pathname?
> 
> if (IS_DIR_SEPARATOR (ptr[ptr[0] == '.']) // ./FOO or /FOO
> #if HAVE_DOS_BASED_FILE_SYSTEM
>      // DOS-FS IS_ABSOLUTE_PATH thinks 'A:B' is absolute, but we need to 
> consider
>      // that as a module:partition.
>      || (HAS_DRIVE_SPEC (ptr) && IS_DIR_SEPARATOR (ptr[2])) // A:/FOO
> #endif
>      || false)
>     return ....
> 
> Does (something like) that work?

I tested it and your solution appears to work.
Are you okay with me pushing that solution or do you want me to send a 
v2 with it first?

Kind regards,
Torbjörn

> 
> nathan
> 
>>
>>
>> Let me know what you prefer.
>>
>> Kind regards,
>> Torbjörn
>>
>>>
>>> nathan
>>>
>>>>
>>>> gcc/cp/ChangeLog:
>>>>
>>>>     * module.cc: Use IS_REAL_ABSOLUTE_PATH macro.
>>>>
>>>> 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 | 4 ++++
>>>>   2 files changed, 5 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..d04fccfed64 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,8 @@ 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) \
>>>> +  ((f)[0] && (f)[1] == ':' && ((f)[2] == '/' || (f)[2] == '\\'))
>>>>   #define HAS_DOS_DRIVE_SPEC(f) HAS_DRIVE_SPEC_1 (1, f)
>>>>   #define IS_UNIX_DIR_SEPARATOR(c) IS_DIR_SEPARATOR_1 (0, c)
>>>
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] c++: Allow module name to be a single letter on Windows
  2022-11-08 10:18       ` Torbjorn SVENSSON
@ 2022-11-08 12:10         ` Nathan Sidwell
  0 siblings, 0 replies; 6+ messages in thread
From: Nathan Sidwell @ 2022-11-08 12:10 UTC (permalink / raw)
  To: Torbjorn SVENSSON, gcc-patches; +Cc: yvan.roux

On 11/8/22 05:18, Torbjorn SVENSSON wrote:
> Hi Nathan,
> 
> On 2022-11-08 00:03, Nathan Sidwell wrote:

>>
>> Yes, something like the above, but I think you're missing "/bob' in the 
>> DOS_BASED case?  shouldn't that also be a pathname?
>>
>> if (IS_DIR_SEPARATOR (ptr[ptr[0] == '.']) // ./FOO or /FOO
>> #if HAVE_DOS_BASED_FILE_SYSTEM
>>      // DOS-FS IS_ABSOLUTE_PATH thinks 'A:B' is absolute, but we need to consider
>>      // that as a module:partition.
>>      || (HAS_DRIVE_SPEC (ptr) && IS_DIR_SEPARATOR (ptr[2])) // A:/FOO
>> #endif
>>      || false)
>>     return ....
>>
>> Does (something like) that work?
> 
> I tested it and your solution appears to work.
> Are you okay with me pushing that solution or do you want me to send a v2 with 
> it first?

I think it needs a better introductory comment than the one I slapped in there. 
More explanation of the drive vs partition distinction.  Something along the 
lines of 'things that clearly start as pathnames are header-names, everything 
else is treated as a (possibly malformed) named module.

Feel free to just go with it, or iterate here

nathan

-- 
Nathan Sidwell


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-11-08 12:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-28  9:15 [PATCH] c++: Allow module name to be a single letter on Windows Torbjörn SVENSSON
2022-11-03 14:17 ` Nathan Sidwell
2022-11-03 15:06   ` Torbjorn SVENSSON
2022-11-07 23:03     ` Nathan Sidwell
2022-11-08 10:18       ` Torbjorn SVENSSON
2022-11-08 12:10         ` Nathan Sidwell

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).