]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Add clang specific warning suppression macros
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Tue, 12 Sep 2023 18:45:24 +0000 (15:45 -0300)
committerH.J. Lu <hjl.tools@gmail.com>
Sun, 22 Dec 2024 05:29:20 +0000 (13:29 +0800)
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.

Reviewed-by: Sam James <sam@gentoo.org>
include/libc-diag.h

index 4b1c916756a0f8b08dd614773f2c1fcc128c4edd..7666a386f359a00b4e977a69da4dec09c42c3a50 100644 (file)
 /* 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)
 
 # 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 */