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:
parent
e36c1a7476
commit
f12aa97aab
11
gcc_compat.h
11
gcc_compat.h
@ -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 */
|
||||
|
14
xlat/gen.sh
14
xlat/gen.sh
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user