00db10
Partial backport of this upstream commit:
00db10
00db10
commit e15f7de60c26bb75fe1923b17c5f0461164d1a41
00db10
Author: Zack Weinberg <zackw@panix.com>
00db10
Date:   Sun Nov 20 20:46:30 2016 -0500
00db10
00db10
    Split DIAG_* macros to new header libc-diag.h.
00db10
00db10
Only the include/libc-diag.h header file is added.
00db10
00db10
diff --git a/include/libc-diag.h b/include/libc-diag.h
00db10
new file mode 100644
00db10
index 0000000000000000..db138c63b1573256
00db10
--- /dev/null
00db10
+++ b/include/libc-diag.h
00db10
@@ -0,0 +1,74 @@
00db10
+/* Macros for controlling diagnostic output from the compiler.
00db10
+   Copyright (C) 2014-2017 Free Software Foundation, Inc.
00db10
+   This file is part of the GNU C Library.
00db10
+
00db10
+   The GNU C Library is free software; you can redistribute it and/or
00db10
+   modify it under the terms of the GNU Lesser General Public
00db10
+   License as published by the Free Software Foundation; either
00db10
+   version 2.1 of the License, or (at your option) any later version.
00db10
+
00db10
+   The GNU C Library is distributed in the hope that it will be useful,
00db10
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
+   Lesser General Public License for more details.
00db10
+
00db10
+   You should have received a copy of the GNU Lesser General Public
00db10
+   License along with the GNU C Library; if not, see
00db10
+   <http://www.gnu.org/licenses/>.  */
00db10
+
00db10
+#ifndef _LIBC_DIAG_H
00db10
+#define _LIBC_DIAG_H 1
00db10
+
00db10
+/* Ignore the value of an expression when a cast to void does not
00db10
+   suffice (in particular, for a call to a function declared with
00db10
+   attribute warn_unused_result).  */
00db10
+#define ignore_value(x) \
00db10
+  ({ __typeof__ (x) __ignored_value = (x); (void) __ignored_value; })
00db10
+
00db10
+/* The macros to control diagnostics are structured like this, rather
00db10
+   than a single macro that both pushes and pops diagnostic state and
00db10
+   takes the affected code as an argument, because the GCC pragmas
00db10
+   work by disabling the diagnostic for a range of source locations
00db10
+   and do not work when all the pragmas and the affected code are in a
00db10
+   single macro expansion.  */
00db10
+
00db10
+/* Push diagnostic state.  */
00db10
+#define DIAG_PUSH_NEEDS_COMMENT _Pragma ("GCC diagnostic push")
00db10
+
00db10
+/* Pop diagnostic state.  */
00db10
+#define DIAG_POP_NEEDS_COMMENT _Pragma ("GCC diagnostic pop")
00db10
+
00db10
+#define _DIAG_STR1(s) #s
00db10
+#define _DIAG_STR(s) _DIAG_STR1(s)
00db10
+
00db10
+/* Ignore the diagnostic OPTION.  VERSION is the most recent GCC
00db10
+   version for which the diagnostic has been confirmed to appear in
00db10
+   the absence of the pragma (in the form MAJOR.MINOR for GCC 4.x,
00db10
+   just MAJOR for GCC 5 and later).  Uses of this pragma should be
00db10
+   reviewed when the GCC version given is no longer supported for
00db10
+   building glibc; the version number should always be on the same
00db10
+   source line as the macro name, so such uses can be found with grep.
00db10
+   Uses should come with a comment giving more details of the
00db10
+   diagnostic, and an architecture on which it is seen if possibly
00db10
+   optimization-related and not in architecture-specific code.  This
00db10
+   macro should only be used if the diagnostic seems hard to fix (for
00db10
+   example, optimization-related false positives).  */
00db10
+#define DIAG_IGNORE_NEEDS_COMMENT(version, option)     \
00db10
+  _Pragma (_DIAG_STR (GCC diagnostic ignored option))
00db10
+
00db10
+/* Similar to DIAG_IGNORE_NEEDS_COMMENT the following macro ignores the
00db10
+   diagnostic OPTION but only if optimizations for size are enabled.
00db10
+   This is required because different warnings may be generated for
00db10
+   different optimization levels.  For example a key piece of code may
00db10
+   only generate a warning when compiled at -Os, but at -O2 you could
00db10
+   still want the warning to be enabled to catch errors.  In this case
00db10
+   you would use DIAG_IGNORE_Os_NEEDS_COMMENT to disable the warning
00db10
+   only for -Os.  */
00db10
+#ifdef __OPTIMIZE_SIZE__
00db10
+# define DIAG_IGNORE_Os_NEEDS_COMMENT(version, option) \
00db10
+  _Pragma (_DIAG_STR (GCC diagnostic ignored option))
00db10
+#else
00db10
+# define DIAG_IGNORE_Os_NEEDS_COMMENT(version, option)
00db10
+#endif
00db10
+
00db10
+#endif /* libc-diag.h */