From f12aa97aab4336e2203cebcdf1b1b3004be758f3 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Sun, 29 Apr 2018 21:59:55 +0000 Subject: [PATCH] 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 --- gcc_compat.h | 11 +++++++++++ xlat/gen.sh | 14 ++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/gcc_compat.h b/gcc_compat.h index 771286aa..251080bb 100644 --- a/gcc_compat.h +++ b/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 */ diff --git a/xlat/gen.sh b/xlat/gen.sh index aff79922..82e246c5 100755 --- a/xlat/gen.sh +++ b/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. -- 2.40.0