[glibc/azanella/clang] nss: Suppress nss_module.c warning on clang

Adhemerval Zanella azanella@sourceware.org
Fri Jun 3 14:04:24 GMT 2022


https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=a94897810c26e7adfa0519ee2c64f753200a3624

commit a94897810c26e7adfa0519ee2c64f753200a3624
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Thu Mar 10 08:31:06 2022 -0300

    nss: Suppress nss_module.c warning on clang

Diff:
---
 include/libc-diag.h | 13 +++++++++++++
 nss/nss_module.c    |  7 +++++++
 2 files changed, 20 insertions(+)

diff --git a/include/libc-diag.h b/include/libc-diag.h
index e1dbe99eb3..61e33d6c36 100644
--- a/include/libc-diag.h
+++ b/include/libc-diag.h
@@ -71,6 +71,19 @@
 # define DIAG_IGNORE_Os_NEEDS_COMMENT(version, option)
 #endif
 
+/* Same as before, but only enables the warning suppression for clang.
+   It is for clang-only issues and options that only clang emits.  */
+#ifdef __clang__
+# define DIAG_PUSH_NEEDS_COMMENT_CLANG _Pragma ("clang diagnostic push")
+# define DIAG_POP_NEEDS_COMMENT_CLANG _Pragma ("clang diagnostic pop")
+# define DIAG_IGNORE_NEEDS_COMMENT_CLANG(version, option) \
+  _Pragma (_DIAG_STR (clang diagnostic ignored option))
+#else
+# define DIAG_PUSH_NEEDS_COMMENT_CLANG
+# define DIAG_POP_NEEDS_COMMENT_CLANG
+# define DIAG_IGNORE_NEEDS_COMMENT_CLANG(version, option)
+#endif
+
 /* Some warnings are not support for all compilers.  */
 #ifndef __clang__
 # define DIAG_IGNORE_NEEDS_COMMENT_GCC(VERSION, WARNING) \
diff --git a/nss/nss_module.c b/nss/nss_module.c
index f00bbd9e1a..852dc991b4 100644
--- a/nss/nss_module.c
+++ b/nss/nss_module.c
@@ -33,6 +33,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sysdep.h>
+#include <libc-diag.h>
 
 /* Suffix after .so of NSS service modules.  This is a bit of magic,
    but we assume LIBNSS_FILES_SO looks like "libnss_files.so.2" and we
@@ -40,8 +41,14 @@
    except through the auto-generated lib-names.h and some static
    pointer manipulation.  The "-1" accounts for the trailing NUL
    included in the sizeof.  */
+
+/* clang issues an warning adding 'unsigned long' to a string does not append
+   to the string, however it is exactly what code means here.  */
+DIAG_PUSH_NEEDS_COMMENT_CLANG;
+DIAG_IGNORE_NEEDS_COMMENT_CLANG (13, "-Wstring-plus-int");
 static const char *const __nss_shlib_revision
 	= LIBNSS_FILES_SO + sizeof("libnss_files.so") - 1;
+DIAG_POP_NEEDS_COMMENT_CLANG;
 
 /* A single-linked list used to implement a mapping from service names
    to NSS modules.  (Most systems only use five or so modules, so a


More information about the Glibc-cvs mailing list