public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH v3] c++: Allow module name to be a single letter on Windows
@ 2022-11-17 13:20 Torbjörn SVENSSON
  2022-11-25 19:03 ` PING " Torbjorn SVENSSON
  0 siblings, 1 reply; 4+ messages in thread
From: Torbjörn SVENSSON @ 2022-11-17 13:20 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.

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 <yvan.roux@foss.st.com>
Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
---
 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));
 
-- 
2.25.1


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

* PING [PATCH v3] c++: Allow module name to be a single letter on Windows
  2022-11-17 13:20 [PATCH v3] c++: Allow module name to be a single letter on Windows Torbjörn SVENSSON
@ 2022-11-25 19:03 ` Torbjorn SVENSSON
  2022-11-28 11:21   ` Nathan Sidwell
  0 siblings, 1 reply; 4+ messages in thread
From: Torbjorn SVENSSON @ 2022-11-25 19:03 UTC (permalink / raw)
  To: gcc-patches; +Cc: nathan, yvan.roux

Hi,

Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-November/606528.html

Kind regards,
Torbjörn

On 2022-11-17 14:20, Torbjörn SVENSSON wrote:
> 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 <yvan.roux@foss.st.com>
> Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
> ---
>   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));
>   

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

* Re: PING [PATCH v3] c++: Allow module name to be a single letter on Windows
  2022-11-25 19:03 ` PING " Torbjorn SVENSSON
@ 2022-11-28 11:21   ` Nathan Sidwell
  2022-11-28 15:50     ` Torbjorn SVENSSON
  0 siblings, 1 reply; 4+ messages in thread
From: Nathan Sidwell @ 2022-11-28 11:21 UTC (permalink / raw)
  To: Torbjorn SVENSSON, gcc-patches; +Cc: yvan.roux

On 11/25/22 14:03, Torbjorn SVENSSON wrote:
> Hi,
> 
> Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-November/606528.html

ok, thanks!

> 
> Kind regards,
> Torbjörn
> 
> On 2022-11-17 14:20, Torbjörn SVENSSON wrote:
>> 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 <yvan.roux@foss.st.com>
>> Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
>> ---
>>   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));

-- 
Nathan Sidwell


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

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



On 2022-11-28 12:21, Nathan Sidwell wrote:
> On 11/25/22 14:03, Torbjorn SVENSSON wrote:
>> Hi,
>>
>> Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-November/606528.html
> 
> ok, thanks!

Pushed.

> 
>>
>> Kind regards,
>> Torbjörn
>>
>> On 2022-11-17 14:20, Torbjörn SVENSSON wrote:
>>> 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 <yvan.roux@foss.st.com>
>>> Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
>>> ---
>>>   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));
> 

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

end of thread, other threads:[~2022-11-28 15:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-17 13:20 [PATCH v3] c++: Allow module name to be a single letter on Windows Torbjörn SVENSSON
2022-11-25 19:03 ` PING " Torbjorn SVENSSON
2022-11-28 11:21   ` Nathan Sidwell
2022-11-28 15:50     ` Torbjorn 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).