xlat: check that system definitions match fallback definitions

For each constant that is accompanied by a fallback definition,
generate a sanity check that the definition provided by system headers
matches the fallback definition.

* gcc_compat.h (DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE,
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE): New macros.
* xlat/gen.sh (cond_def): Generate a code that checks the system
definition against the default.
(gen_header): Generate a code that includes "gcc_compat.h" and
"static_assert.h".

Co-Authored-by: Eugene Syromyatnikov <evgsyr@gmail.com>
This commit is contained in:
Дмитрий Левин 2018-04-29 21:59:55 +00:00
parent e36c1a7476
commit f12aa97aab
2 changed files with 23 additions and 2 deletions

View File

@ -99,4 +99,15 @@
# define ATTRIBUTE_FALLTHROUGH ((void) 0)
#endif
#if GNUC_PREREQ(6, 0)
# define DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE \
_Pragma("GCC diagnostic push"); \
_Pragma("GCC diagnostic ignored \"-Wtautological-compare\"");
# define DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE \
_Pragma("GCC diagnostic pop");
#else
# define DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE /* empty */
# define DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE /* empty */
#endif
#endif /* !STRACE_GCC_COMPAT_H */

View File

@ -53,7 +53,11 @@ cond_def()
if [ -n "$def" ]; then
cat <<-EOF
#if !(defined($val) || (defined(HAVE_DECL_$val) && HAVE_DECL_$val))
#if defined($val) || (defined(HAVE_DECL_$val) && HAVE_DECL_$val)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
static_assert(($val) == ($def), "$val != $def");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
# define $val $def
#endif
EOF
@ -133,7 +137,13 @@ gen_header()
in_mpers=1
fi
echo "/* Generated by $0 from $1; do not edit. */"
cat <<-EOF
/* Generated by $0 from $1; do not edit. */
#include "gcc_compat.h"
#include "static_assert.h"
EOF
local unconditional= line
# 1st pass: output directives.