stdlib: DIAG_IGNORE_NEEDS_COMMENT setenv.c

Message ID 20220829190021.946508-1-adhemerval.zanella@linaro.org
State Superseded
Headers
Series stdlib: DIAG_IGNORE_NEEDS_COMMENT setenv.c |

Checks

Context Check Description
dj/TryBot-32bit success Build for i686
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Adhemerval Zanella Netto Aug. 29, 2022, 7 p.m. UTC
  Checked on x86_64-linux-gnu.
---
 stdlib/setenv.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
  

Comments

Florian Weimer Aug. 30, 2022, 7:15 a.m. UTC | #1
* Adhemerval Zanella via Libc-alpha:

> Checked on x86_64-linux-gnu.
> ---
>  stdlib/setenv.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/stdlib/setenv.c b/stdlib/setenv.c
> index 2176cbac31..2add8bfb41 100644
> --- a/stdlib/setenv.c
> +++ b/stdlib/setenv.c
> @@ -19,12 +19,14 @@
>  # include <config.h>
>  #endif
>  
> +#if _LIBC
> +# include <libc-diag.h>
>  /* Pacify GCC; see the commentary about VALLEN below.  This is needed
>     at least through GCC 4.9.2.  Pacify GCC for the entire file, as
>     there seems to be no way to pacify GCC selectively, only for the
> -   place where it's needed.  Do not use DIAG_IGNORE_NEEDS_COMMENT
> -   here, as it's not defined yet.  */
> -#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
> +   place where it's needed.  */
> +DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wmaybe-uninitialized");
> +#endif

The comment was added in:

commit 03c1e456b079929a8290aeb4aadb05c0df73bfd2
Author: Paul Eggert <eggert@cs.ucla.edu>
Date:   Sun Apr 19 01:06:33 2015 -0700

    Better fix for setenv (..., NULL, ...)
    
    * stdlib/setenv.c (__add_to_environ):
    Dump core quickly if setenv (..., NULL, ...) is called.
    This time, do it the right way, and pacify GCC with a pragma.

Paul, what did you mean when you wrote “not defined yet”?  Is it a
gnulib thing?

Thanks,
Florian
  
Adhemerval Zanella Netto Sept. 19, 2022, 2:05 p.m. UTC | #2
On 30/08/22 04:15, Florian Weimer wrote:
> * Adhemerval Zanella via Libc-alpha:
> 
>> Checked on x86_64-linux-gnu.
>> ---
>>  stdlib/setenv.c | 8 +++++---
>>  1 file changed, 5 insertions(+), 3 deletions(-)
>>
>> diff --git a/stdlib/setenv.c b/stdlib/setenv.c
>> index 2176cbac31..2add8bfb41 100644
>> --- a/stdlib/setenv.c
>> +++ b/stdlib/setenv.c
>> @@ -19,12 +19,14 @@
>>  # include <config.h>
>>  #endif
>>  
>> +#if _LIBC
>> +# include <libc-diag.h>
>>  /* Pacify GCC; see the commentary about VALLEN below.  This is needed
>>     at least through GCC 4.9.2.  Pacify GCC for the entire file, as
>>     there seems to be no way to pacify GCC selectively, only for the
>> -   place where it's needed.  Do not use DIAG_IGNORE_NEEDS_COMMENT
>> -   here, as it's not defined yet.  */
>> -#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
>> +   place where it's needed.  */
>> +DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wmaybe-uninitialized");
>> +#endif
> 
> The comment was added in:
> 
> commit 03c1e456b079929a8290aeb4aadb05c0df73bfd2
> Author: Paul Eggert <eggert@cs.ucla.edu>
> Date:   Sun Apr 19 01:06:33 2015 -0700
> 
>     Better fix for setenv (..., NULL, ...)
>     
>     * stdlib/setenv.c (__add_to_environ):
>     Dump core quickly if setenv (..., NULL, ...) is called.
>     This time, do it the right way, and pacify GCC with a pragma.
> 
> Paul, what did you mean when you wrote “not defined yet”?  Is it a
> gnulib thing?

Paul, is anything to prevent us to use DIAG_IGNORE_NEEDS_COMMENT here?
For glibc it is the best way to possible handle different compiler that
might not need to define it.
  

Patch

diff --git a/stdlib/setenv.c b/stdlib/setenv.c
index 2176cbac31..2add8bfb41 100644
--- a/stdlib/setenv.c
+++ b/stdlib/setenv.c
@@ -19,12 +19,14 @@ 
 # include <config.h>
 #endif
 
+#if _LIBC
+# include <libc-diag.h>
 /* Pacify GCC; see the commentary about VALLEN below.  This is needed
    at least through GCC 4.9.2.  Pacify GCC for the entire file, as
    there seems to be no way to pacify GCC selectively, only for the
-   place where it's needed.  Do not use DIAG_IGNORE_NEEDS_COMMENT
-   here, as it's not defined yet.  */
-#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+   place where it's needed.  */
+DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wmaybe-uninitialized");
+#endif
 
 #include <errno.h>
 #if !_LIBC