diff mbox series

gcc: Make strchr return value pointers const

Message ID 20200901130142.6366-1-martin@martin.st
State Accepted
Commit 3fe3efe5c141a88a80c1ecc6aebc7f15d6426f62
Headers show
Series gcc: Make strchr return value pointers const | expand

Commit Message

Martin Storsjo Sept. 1, 2020, 1:01 p.m. UTC
This fixes compilation of codepaths for dos-like filesystems
with Clang. When built with clang, it treats C input files as C++
when the compiler driver is invoked in C++ mode, triggering errors
when the return value of strchr() on a pointer to const is assigned
to a pointer to non-const variable.

This matches similar variables outside of the ifdefs for dos-like
path handling.

2020-09-01  Martin Storsjö  <martin@martin.st>

gcc/Changelog:
        * dwarf2out.c (file_name_acquire): Make a strchr return value
        pointer to const.

libcpp/Changelog:
        * files.c (remap_filename): Make a strchr return value pointer
        to const.
---
 gcc/dwarf2out.c | 2 +-
 libcpp/files.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

-- 
2.17.1

Comments

Richard Sandiford via Gcc-patches Sept. 4, 2020, 9:21 a.m. UTC | #1
On 9/1/20 1:01 PM, Martin Storsjö wrote:
> This fixes compilation of codepaths for dos-like filesystems

> with Clang. When built with clang, it treats C input files as C++

> when the compiler driver is invoked in C++ mode, triggering errors

> when the return value of strchr() on a pointer to const is assigned

> to a pointer to non-const variable.

> 


Ping any reviewers?
Richard Sandiford via Gcc-patches Sept. 4, 2020, 9:32 a.m. UTC | #2
On Tue, Sep 01, 2020 at 04:01:42PM +0300, Martin Storsjö wrote:
> This fixes compilation of codepaths for dos-like filesystems

> with Clang. When built with clang, it treats C input files as C++

> when the compiler driver is invoked in C++ mode, triggering errors

> when the return value of strchr() on a pointer to const is assigned

> to a pointer to non-const variable.


Not really specific to clang, e.g. glibc does that in its headers too
as the C++ standard mandates that (and I guess mingw should do that too).

> This matches similar variables outside of the ifdefs for dos-like

> path handling.

> 

> 2020-09-01  Martin Storsjö  <martin@martin.st>

> 

> gcc/Changelog:

>         * dwarf2out.c (file_name_acquire): Make a strchr return value

>         pointer to const.

> 

> libcpp/Changelog:

>         * files.c (remap_filename): Make a strchr return value pointer

>         to const.


LGTM.  And it is short enough not to need copyright assignment, so ok for
trunk.

> ---

>  gcc/dwarf2out.c | 2 +-

>  libcpp/files.c  | 2 +-

>  2 files changed, 2 insertions(+), 2 deletions(-)

> 

> diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c

> index b6ab49bb548..4096c0c0d69 100644

> --- a/gcc/dwarf2out.c

> +++ b/gcc/dwarf2out.c

> @@ -12118,7 +12118,7 @@ file_name_acquire (dwarf_file_data **slot, file_name_acquire_data *fnad)

>    f = strrchr (f, DIR_SEPARATOR);

>  #if defined (DIR_SEPARATOR_2)

>    {

> -    char *g = strrchr (fi->path, DIR_SEPARATOR_2);

> +    const char *g = strrchr (fi->path, DIR_SEPARATOR_2);

>  

>      if (g != NULL)

>        {

> diff --git a/libcpp/files.c b/libcpp/files.c

> index 3d48c38fc0a..b890b8ebf1e 100644

> --- a/libcpp/files.c

> +++ b/libcpp/files.c

> @@ -1693,7 +1693,7 @@ remap_filename (cpp_reader *pfile, _cpp_file *file)

>        p = strchr (fname, '/');

>  #ifdef HAVE_DOS_BASED_FILE_SYSTEM

>        {

> -	char *p2 = strchr (fname, '\\');

> +	const char *p2 = strchr (fname, '\\');

>  	if (!p || (p > p2))

>  	  p = p2;

>        }

> -- 

> 2.17.1


	Jakub
Martin Storsjo Sept. 4, 2020, 12:47 p.m. UTC | #3
Hi,

On Fri, 4 Sep 2020, Jakub Jelinek wrote:

> On Tue, Sep 01, 2020 at 04:01:42PM +0300, Martin Storsjö wrote:

>> This fixes compilation of codepaths for dos-like filesystems

>> with Clang. When built with clang, it treats C input files as C++

>> when the compiler driver is invoked in C++ mode, triggering errors

>> when the return value of strchr() on a pointer to const is assigned

>> to a pointer to non-const variable.

>

> Not really specific to clang, e.g. glibc does that in its headers too

> as the C++ standard mandates that (and I guess mingw should do that too).

>

>> This matches similar variables outside of the ifdefs for dos-like

>> path handling.

>>

>> 2020-09-01  Martin Storsjö  <martin@martin.st>

>>

>> gcc/Changelog:

>>         * dwarf2out.c (file_name_acquire): Make a strchr return value

>>         pointer to const.

>>

>> libcpp/Changelog:

>>         * files.c (remap_filename): Make a strchr return value pointer

>>         to const.

>

> LGTM.  And it is short enough not to need copyright assignment, so ok for

> trunk.


Thanks! Can someone commit this for me?

// Martin
Richard Sandiford via Gcc-patches Sept. 8, 2020, 12:13 a.m. UTC | #4
On 9/4/20 12:47 PM, Martin Storsjö wrote:
> Hi,

> 

> On Fri, 4 Sep 2020, Jakub Jelinek wrote:

> 

>> On Tue, Sep 01, 2020 at 04:01:42PM +0300, Martin Storsjö wrote:

>>> This fixes compilation of codepaths for dos-like filesystems

>>> with Clang. When built with clang, it treats C input files as C++

>>> when the compiler driver is invoked in C++ mode, triggering errors

>>> when the return value of strchr() on a pointer to const is assigned

>>> to a pointer to non-const variable.

>>

>> Not really specific to clang, e.g. glibc does that in its headers too

>> as the C++ standard mandates that (and I guess mingw should do that too).

>>

>>> This matches similar variables outside of the ifdefs for dos-like

>>> path handling.

>>>

>>> 2020-09-01  Martin Storsjö  <martin@martin.st>

>>>

>>> gcc/Changelog:

>>>         * dwarf2out.c (file_name_acquire): Make a strchr return value

>>>         pointer to const.

>>>

>>> libcpp/Changelog:

>>>         * files.c (remap_filename): Make a strchr return value pointer

>>>         to const.

>>

>> LGTM.  And it is short enough not to need copyright assignment, so ok for

>> trunk.

> 

> Thanks! Can someone commit this for me?

> 

> // Martin


Ping can anyone commit this?

Are platform maintainers allowed to push general changes like these? If
so I can push soon.
Richard Sandiford Sept. 8, 2020, 11:16 a.m. UTC | #5
JonY via Gcc-patches <gcc-patches@gcc.gnu.org> writes:
> On 9/4/20 12:47 PM, Martin Storsjö wrote:

>> Hi,

>> 

>> On Fri, 4 Sep 2020, Jakub Jelinek wrote:

>> 

>>> On Tue, Sep 01, 2020 at 04:01:42PM +0300, Martin Storsjö wrote:

>>>> This fixes compilation of codepaths for dos-like filesystems

>>>> with Clang. When built with clang, it treats C input files as C++

>>>> when the compiler driver is invoked in C++ mode, triggering errors

>>>> when the return value of strchr() on a pointer to const is assigned

>>>> to a pointer to non-const variable.

>>>

>>> Not really specific to clang, e.g. glibc does that in its headers too

>>> as the C++ standard mandates that (and I guess mingw should do that too).

>>>

>>>> This matches similar variables outside of the ifdefs for dos-like

>>>> path handling.

>>>>

>>>> 2020-09-01  Martin Storsjö  <martin@martin.st>

>>>>

>>>> gcc/Changelog:

>>>>         * dwarf2out.c (file_name_acquire): Make a strchr return value

>>>>         pointer to const.

>>>>

>>>> libcpp/Changelog:

>>>>         * files.c (remap_filename): Make a strchr return value pointer

>>>>         to const.

>>>

>>> LGTM.  And it is short enough not to need copyright assignment, so ok for

>>> trunk.

>> 

>> Thanks! Can someone commit this for me?

>> 

>> // Martin

>

> Ping can anyone commit this?

>

> Are platform maintainers allowed to push general changes like these? If

> so I can push soon.


Yeah, anyone with commit access can push an approved patch.

Richard
Richard Sandiford via Gcc-patches Sept. 8, 2020, 11:50 a.m. UTC | #6
On Tue, Sep 08, 2020 at 12:16:08PM +0100, Richard Sandiford wrote:
> > Are platform maintainers allowed to push general changes like these? If

> > so I can push soon.

> 

> Yeah, anyone with commit access can push an approved patch.


I've pushed this one yesterday already:
https://gcc.gnu.org/g:3fe3efe5c141a88a80c1ecc6aebc7f15d6426f62

Anyway, with git I'd like to say that it is desirable to commit
such patches with git commit --author '...' to give due credit.

	Jakub
Martin Storsjo Sept. 8, 2020, 12:03 p.m. UTC | #7
On Tue, 8 Sep 2020, Jakub Jelinek wrote:

> On Tue, Sep 08, 2020 at 12:16:08PM +0100, Richard Sandiford wrote:

>>> Are platform maintainers allowed to push general changes like these? If

>>> so I can push soon.

>>

>> Yeah, anyone with commit access can push an approved patch.

>

> I've pushed this one yesterday already:

> https://gcc.gnu.org/g:3fe3efe5c141a88a80c1ecc6aebc7f15d6426f62


Thanks!

// Martin
Richard Sandiford via Gcc-patches Sept. 17, 2020, 3:56 a.m. UTC | #8
On 9/7/20 6:13 PM, JonY via Gcc-patches wrote:
> On 9/4/20 12:47 PM, Martin Storsjö wrote:

>> Hi,

>>

>> On Fri, 4 Sep 2020, Jakub Jelinek wrote:

>>

>>> On Tue, Sep 01, 2020 at 04:01:42PM +0300, Martin Storsjö wrote:

>>>> This fixes compilation of codepaths for dos-like filesystems

>>>> with Clang. When built with clang, it treats C input files as C++

>>>> when the compiler driver is invoked in C++ mode, triggering errors

>>>> when the return value of strchr() on a pointer to const is assigned

>>>> to a pointer to non-const variable.

>>> Not really specific to clang, e.g. glibc does that in its headers too

>>> as the C++ standard mandates that (and I guess mingw should do that too).

>>>

>>>> This matches similar variables outside of the ifdefs for dos-like

>>>> path handling.

>>>>

>>>> 2020-09-01  Martin Storsjö  <martin@martin.st>

>>>>

>>>> gcc/Changelog:

>>>>         * dwarf2out.c (file_name_acquire): Make a strchr return value

>>>>         pointer to const.

>>>>

>>>> libcpp/Changelog:

>>>>         * files.c (remap_filename): Make a strchr return value pointer

>>>>         to const.

>>> LGTM.  And it is short enough not to need copyright assignment, so ok for

>>> trunk.

>> Thanks! Can someone commit this for me?

>>

>> // Martin

> Ping can anyone commit this?

>

> Are platform maintainers allowed to push general changes like these? If

> so I can push soon.


If it's been ack'd by a maintainer, yes.  Jakub definitely qualifies as
a maintainer, so feel free to push it on Martin's behalf.


jeff

>
Richard Sandiford via Gcc-patches Sept. 17, 2020, 6:19 a.m. UTC | #9
On 9/17/20 3:56 AM, Jeff Law wrote:
> 

> If it's been ack'd by a maintainer, yes.  Jakub definitely qualifies as

> a maintainer, so feel free to push it on Martin's behalf.

> 

> 

> jeff


Sure, it has been pushed, thanks all.
diff mbox series

Patch

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index b6ab49bb548..4096c0c0d69 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -12118,7 +12118,7 @@  file_name_acquire (dwarf_file_data **slot, file_name_acquire_data *fnad)
   f = strrchr (f, DIR_SEPARATOR);
 #if defined (DIR_SEPARATOR_2)
   {
-    char *g = strrchr (fi->path, DIR_SEPARATOR_2);
+    const char *g = strrchr (fi->path, DIR_SEPARATOR_2);
 
     if (g != NULL)
       {
diff --git a/libcpp/files.c b/libcpp/files.c
index 3d48c38fc0a..b890b8ebf1e 100644
--- a/libcpp/files.c
+++ b/libcpp/files.c
@@ -1693,7 +1693,7 @@  remap_filename (cpp_reader *pfile, _cpp_file *file)
       p = strchr (fname, '/');
 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
       {
-	char *p2 = strchr (fname, '\\');
+	const char *p2 = strchr (fname, '\\');
 	if (!p || (p > p2))
 	  p = p2;
       }