diff mbox series

Add clang specific warnings suppress macros

Message ID 20241221222300.753331-1-hjl.tools@gmail.com
State Superseded
Headers show
Series Add clang specific warnings suppress macros | expand

Commit Message

H.J. Lu Dec. 21, 2024, 10:23 p.m. UTC
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>

Four new macros are added:

  * DIAG_{PUSH,POP}_NEEDS_COMMENT_CLANG are similar to
    DIAG_{PUSH,POP}_NEEDS_COMMENT, but enable clang specific pragmas to
    handle warnings for options only supported by clang.

  * DIAG_IGNORE_NEEDS_COMMENT_{CLANG,GCC} are similar to
    DIAG_IGNORE_NEEDS_COMMENT, but enable the warning suppression only
    for the referenced compiler.
---
 include/libc-diag.h | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

Comments

H.J. Lu Dec. 21, 2024, 10:36 p.m. UTC | #1
On Sun, Dec 22, 2024 at 6:23 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
>
> Four new macros are added:
>
>   * DIAG_{PUSH,POP}_NEEDS_COMMENT_CLANG are similar to
>     DIAG_{PUSH,POP}_NEEDS_COMMENT, but enable clang specific pragmas to
>     handle warnings for options only supported by clang.
>
>   * DIAG_IGNORE_NEEDS_COMMENT_{CLANG,GCC} are similar to
>     DIAG_IGNORE_NEEDS_COMMENT, but enable the warning suppression only
>     for the referenced compiler.
> ---
>  include/libc-diag.h | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
>
> diff --git a/include/libc-diag.h b/include/libc-diag.h
> index 4b1c916756..7666a386f3 100644
> --- a/include/libc-diag.h
> +++ b/include/libc-diag.h
> @@ -38,6 +38,16 @@
>  /* Pop diagnostic state.  */
>  #define DIAG_POP_NEEDS_COMMENT _Pragma ("GCC diagnostic pop")
>
> +/* These macros are used to push/pop diagnostic states for warnings only
> +   supported by clang.  */
> +#ifdef __clang__
> +# define DIAG_PUSH_NEEDS_COMMENT_CLANG _Pragma ("clang diagnostic push")
> +# define DIAG_POP_NEEDS_COMMENT_CLANG _Pragma ("clang diagnostic pop")
> +#else
> +# define DIAG_PUSH_NEEDS_COMMENT_CLANG
> +# define DIAG_POP_NEEDS_COMMENT_CLANG
> +#endif
> +
>  #define _DIAG_STR1(s) #s
>  #define _DIAG_STR(s) _DIAG_STR1(s)
>
> @@ -71,4 +81,16 @@
>  # define DIAG_IGNORE_Os_NEEDS_COMMENT(version, option)
>  #endif
>
> +/* Similar to DIAG_IGNORE_NEEDS_COMMENT, these macros should be used
> +   to suppress warning supported by the specific compiler.  */
> +#ifndef __clang__
> +# define DIAG_IGNORE_NEEDS_COMMENT_GCC(VERSION, WARNING) \
> +  DIAG_IGNORE_NEEDS_COMMENT (VERSION, WARNING)
> +# define DIAG_IGNORE_NEEDS_COMMENT_CLANG(version, option)
> +#else
> +# define DIAG_IGNORE_NEEDS_COMMENT_GCC(VERSION, WARNING)
> +# define DIAG_IGNORE_NEEDS_COMMENT_CLANG(version, option) \
> +  _Pragma (_DIAG_STR (clang diagnostic ignored option))
> +#endif
> +
>  #endif /* libc-diag.h */
> --
> 2.47.1
>

This patch is needed by other patches to suppress Clang warnings.
Sam James Dec. 21, 2024, 10:52 p.m. UTC | #2
"H.J. Lu" <hjl.tools@gmail.com> writes:

> On Sun, Dec 22, 2024 at 6:23 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>>
>> From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
>>
>> Four new macros are added:
>>
>>   * DIAG_{PUSH,POP}_NEEDS_COMMENT_CLANG are similar to
>>     DIAG_{PUSH,POP}_NEEDS_COMMENT, but enable clang specific pragmas to
>>     handle warnings for options only supported by clang.
>>
>>   * DIAG_IGNORE_NEEDS_COMMENT_{CLANG,GCC} are similar to
>>     DIAG_IGNORE_NEEDS_COMMENT, but enable the warning suppression only
>>     for the referenced compiler.
>> ---
>>  include/libc-diag.h | 22 ++++++++++++++++++++++
>>  1 file changed, 22 insertions(+)
>>
>> diff --git a/include/libc-diag.h b/include/libc-diag.h
>> index 4b1c916756..7666a386f3 100644
>> --- a/include/libc-diag.h
>> +++ b/include/libc-diag.h
>> @@ -38,6 +38,16 @@
>>  /* Pop diagnostic state.  */
>>  #define DIAG_POP_NEEDS_COMMENT _Pragma ("GCC diagnostic pop")
>>
>> +/* These macros are used to push/pop diagnostic states for warnings only
>> +   supported by clang.  */
>> +#ifdef __clang__
>> +# define DIAG_PUSH_NEEDS_COMMENT_CLANG _Pragma ("clang diagnostic push")
>> +# define DIAG_POP_NEEDS_COMMENT_CLANG _Pragma ("clang diagnostic pop")
>> +#else
>> +# define DIAG_PUSH_NEEDS_COMMENT_CLANG
>> +# define DIAG_POP_NEEDS_COMMENT_CLANG
>> +#endif
>> +
>>  #define _DIAG_STR1(s) #s
>>  #define _DIAG_STR(s) _DIAG_STR1(s)
>>
>> @@ -71,4 +81,16 @@
>>  # define DIAG_IGNORE_Os_NEEDS_COMMENT(version, option)
>>  #endif
>>
>> +/* Similar to DIAG_IGNORE_NEEDS_COMMENT, these macros should be used
>> +   to suppress warning supported by the specific compiler.  */
>> +#ifndef __clang__
>> +# define DIAG_IGNORE_NEEDS_COMMENT_GCC(VERSION, WARNING) \
>> +  DIAG_IGNORE_NEEDS_COMMENT (VERSION, WARNING)
>> +# define DIAG_IGNORE_NEEDS_COMMENT_CLANG(version, option)
>> +#else
>> +# define DIAG_IGNORE_NEEDS_COMMENT_GCC(VERSION, WARNING)
>> +# define DIAG_IGNORE_NEEDS_COMMENT_CLANG(version, option) \
>> +  _Pragma (_DIAG_STR (clang diagnostic ignored option))
>> +#endif
>> +
>>  #endif /* libc-diag.h */
>> --
>> 2.47.1
>>
>
> This patch is needed by other patches to suppress Clang warnings.

Could you send the remaining set as a series if it is not too much
trouble, then I will try get them reviewed tonight (at least the bulk)? Thanks.
H.J. Lu Dec. 21, 2024, 11:01 p.m. UTC | #3
On Sun, Dec 22, 2024 at 6:52 AM Sam James <sam@gentoo.org> wrote:
>
> "H.J. Lu" <hjl.tools@gmail.com> writes:
>
> > On Sun, Dec 22, 2024 at 6:23 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> >>
> >> From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
> >>
> >> Four new macros are added:
> >>
> >>   * DIAG_{PUSH,POP}_NEEDS_COMMENT_CLANG are similar to
> >>     DIAG_{PUSH,POP}_NEEDS_COMMENT, but enable clang specific pragmas to
> >>     handle warnings for options only supported by clang.
> >>
> >>   * DIAG_IGNORE_NEEDS_COMMENT_{CLANG,GCC} are similar to
> >>     DIAG_IGNORE_NEEDS_COMMENT, but enable the warning suppression only
> >>     for the referenced compiler.
> >> ---
> >>  include/libc-diag.h | 22 ++++++++++++++++++++++
> >>  1 file changed, 22 insertions(+)
> >>
> >> diff --git a/include/libc-diag.h b/include/libc-diag.h
> >> index 4b1c916756..7666a386f3 100644
> >> --- a/include/libc-diag.h
> >> +++ b/include/libc-diag.h
> >> @@ -38,6 +38,16 @@
> >>  /* Pop diagnostic state.  */
> >>  #define DIAG_POP_NEEDS_COMMENT _Pragma ("GCC diagnostic pop")
> >>
> >> +/* These macros are used to push/pop diagnostic states for warnings only
> >> +   supported by clang.  */
> >> +#ifdef __clang__
> >> +# define DIAG_PUSH_NEEDS_COMMENT_CLANG _Pragma ("clang diagnostic push")
> >> +# define DIAG_POP_NEEDS_COMMENT_CLANG _Pragma ("clang diagnostic pop")
> >> +#else
> >> +# define DIAG_PUSH_NEEDS_COMMENT_CLANG
> >> +# define DIAG_POP_NEEDS_COMMENT_CLANG
> >> +#endif
> >> +
> >>  #define _DIAG_STR1(s) #s
> >>  #define _DIAG_STR(s) _DIAG_STR1(s)
> >>
> >> @@ -71,4 +81,16 @@
> >>  # define DIAG_IGNORE_Os_NEEDS_COMMENT(version, option)
> >>  #endif
> >>
> >> +/* Similar to DIAG_IGNORE_NEEDS_COMMENT, these macros should be used
> >> +   to suppress warning supported by the specific compiler.  */
> >> +#ifndef __clang__
> >> +# define DIAG_IGNORE_NEEDS_COMMENT_GCC(VERSION, WARNING) \
> >> +  DIAG_IGNORE_NEEDS_COMMENT (VERSION, WARNING)
> >> +# define DIAG_IGNORE_NEEDS_COMMENT_CLANG(version, option)
> >> +#else
> >> +# define DIAG_IGNORE_NEEDS_COMMENT_GCC(VERSION, WARNING)
> >> +# define DIAG_IGNORE_NEEDS_COMMENT_CLANG(version, option) \
> >> +  _Pragma (_DIAG_STR (clang diagnostic ignored option))
> >> +#endif
> >> +
> >>  #endif /* libc-diag.h */
> >> --
> >> 2.47.1
> >>
> >
> > This patch is needed by other patches to suppress Clang warnings.
>
> Could you send the remaining set as a series if it is not too much
> trouble, then I will try get them reviewed tonight (at least the bulk)? Thanks.

Will do.

Thanks.
diff mbox series

Patch

diff --git a/include/libc-diag.h b/include/libc-diag.h
index 4b1c916756..7666a386f3 100644
--- a/include/libc-diag.h
+++ b/include/libc-diag.h
@@ -38,6 +38,16 @@ 
 /* Pop diagnostic state.  */
 #define DIAG_POP_NEEDS_COMMENT _Pragma ("GCC diagnostic pop")
 
+/* These macros are used to push/pop diagnostic states for warnings only
+   supported by clang.  */
+#ifdef __clang__
+# define DIAG_PUSH_NEEDS_COMMENT_CLANG _Pragma ("clang diagnostic push")
+# define DIAG_POP_NEEDS_COMMENT_CLANG _Pragma ("clang diagnostic pop")
+#else
+# define DIAG_PUSH_NEEDS_COMMENT_CLANG
+# define DIAG_POP_NEEDS_COMMENT_CLANG
+#endif
+
 #define _DIAG_STR1(s) #s
 #define _DIAG_STR(s) _DIAG_STR1(s)
 
@@ -71,4 +81,16 @@ 
 # define DIAG_IGNORE_Os_NEEDS_COMMENT(version, option)
 #endif
 
+/* Similar to DIAG_IGNORE_NEEDS_COMMENT, these macros should be used
+   to suppress warning supported by the specific compiler.  */
+#ifndef __clang__
+# define DIAG_IGNORE_NEEDS_COMMENT_GCC(VERSION, WARNING) \
+  DIAG_IGNORE_NEEDS_COMMENT (VERSION, WARNING)
+# define DIAG_IGNORE_NEEDS_COMMENT_CLANG(version, option)
+#else
+# define DIAG_IGNORE_NEEDS_COMMENT_GCC(VERSION, WARNING)
+# define DIAG_IGNORE_NEEDS_COMMENT_CLANG(version, option) \
+  _Pragma (_DIAG_STR (clang diagnostic ignored option))
+#endif
+
 #endif /* libc-diag.h */