From c9d0ef07edcf9f0eb3bc7a6cd62757dbcead59b7 Mon Sep 17 00:00:00 2001 From: Pavel Hrdina Date: Fri, 24 Jul 2020 16:35:03 +0200 Subject: [PATCH] meson: add compiler warnings Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa Reviewed-by: Neal Gompa --- config.h | 7 + configure.ac | 3 - m4/virt-compile-warnings.m4 | 253 ------------------------------------ m4/virt-warnings.m4 | 115 ---------------- meson.build | 232 ++++++++++++++++++++++++++++++--- meson_options.txt | 1 + 6 files changed, 222 insertions(+), 389 deletions(-) delete mode 100644 m4/virt-compile-warnings.m4 delete mode 100644 m4/virt-warnings.m4 diff --git a/config.h b/config.h index 9c433ad4c0..368688f3d0 100644 --- a/config.h +++ b/config.h @@ -1,5 +1,12 @@ #include +/* Enable compile-time and run-time bounds-checking, and some warnings, + * without upsetting newer glibc. */ + +#if !defined _FORTIFY_SOURCE && defined __OPTIMIZE__ && __OPTIMIZE__ +# define _FORTIFY_SOURCE 2 +#endif + #ifndef __GNUC__ # error "Libvirt requires GCC >= 4.8, or CLang" #endif diff --git a/configure.ac b/configure.ac index f006b7dbe0..028624b7c6 100644 --- a/configure.ac +++ b/configure.ac @@ -161,7 +161,6 @@ fi # Check for compiler and library settings. -LIBVIRT_COMPILE_WARNINGS LIBVIRT_LINKER_RELRO LIBVIRT_LINKER_NO_INDIRECT LIBVIRT_LINKER_NO_UNDEFINED @@ -846,8 +845,6 @@ LIBVIRT_WIN_RESULT_WINDRES AC_MSG_NOTICE([]) AC_MSG_NOTICE([Miscellaneous]) AC_MSG_NOTICE([]) -LIBVIRT_RESULT([Use -Werror], [$enable_werror]) -LIBVIRT_RESULT([Warning Flags], [$WARN_CFLAGS]) LIBVIRT_RESULT_DTRACE LIBVIRT_RESULT_NUMAD LIBVIRT_RESULT_INIT_SCRIPT diff --git a/m4/virt-compile-warnings.m4 b/m4/virt-compile-warnings.m4 deleted file mode 100644 index d171d09991..0000000000 --- a/m4/virt-compile-warnings.m4 +++ /dev/null @@ -1,253 +0,0 @@ -dnl -dnl Enable all known GCC compiler warnings, except for those -dnl we can't yet cope with -dnl -AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[ - dnl ****************************** - dnl More compiler warnings - dnl ****************************** - - LIBVIRT_ARG_ENABLE([WERROR], [Use -Werror (if supported)], [check]) - if test "$enable_werror" = "check"; then - if test -d $srcdir/.git; then - is_git_version=true - enable_werror=yes - else - enable_werror=no - fi - fi - - # List of warnings that are not relevant / wanted - - # Don't care about C++ compiler compat - dontwarn="$dontwarn -Wc++-compat" - dontwarn="$dontwarn -Wabi" - dontwarn="$dontwarn -Wdeprecated" - # Don't care about ancient C standard compat - dontwarn="$dontwarn -Wtraditional" - # Don't care about ancient C standard compat - dontwarn="$dontwarn -Wtraditional-conversion" - # Ignore warnings in /usr/include - dontwarn="$dontwarn -Wsystem-headers" - # Happy for compiler to add struct padding - dontwarn="$dontwarn -Wpadded" - # GCC very confused with -O2 - dontwarn="$dontwarn -Wunreachable-code" - # Too many to deal with - dontwarn="$dontwarn -Wconversion" - # Too many to deal with - dontwarn="$dontwarn -Wsign-conversion" - # Need to allow bad cast for execve() - dontwarn="$dontwarn -Wcast-qual" - # We need to use long long in many places - dontwarn="$dontwarn -Wlong-long" - # We allow manual list of all enum cases without default: - dontwarn="$dontwarn -Wswitch-default" - # Not a problem since we don't use -fstrict-overflow - dontwarn="$dontwarn -Wstrict-overflow" - # Not a problem since we don't use -funsafe-loop-optimizations - dontwarn="$dontwarn -Wunsafe-loop-optimizations" - # gcc 4.4.6 complains this is C++ only; gcc 4.7.0 implies this from -Wall - dontwarn="$dontwarn -Wenum-compare" - # gcc 5.1 -Wformat-signedness mishandles enums, not ready for prime time - dontwarn="$dontwarn -Wformat-signedness" - # Several conditionals expand the same on both branches - # depending on the particular platform/architecture - dontwarn="$dontwarn -Wduplicated-branches" - # > This warning does not generally indicate that there is anything wrong - # > with your code; it merely indicates that GCC's optimizers are unable - # > to handle the code effectively. - # Source: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html - dontwarn="$dontwarn -Wdisabled-optimization" - # Various valid glib APIs/macros trigger this warning - dontwarn="$dontwarn -Wbad-function-cast" - - # Broken in 6.0 and later - # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69602 - AC_CACHE_CHECK([whether gcc gives bogus warnings for -Wlogical-op], - [lv_cv_gcc_wlogical_op_equal_expr_broken], [ - save_CFLAGS="$CFLAGS" - CFLAGS="-O2 -Wlogical-op -Werror" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ - #define TEST1 1 - #define TEST2 TEST1 - ]], [[ - int test = 0; - return test == TEST1 || test == TEST2;]])], - [lv_cv_gcc_wlogical_op_equal_expr_broken=no], - [lv_cv_gcc_wlogical_op_equal_expr_broken=yes]) - CFLAGS="$save_CFLAGS"]) - - AC_CACHE_CHECK([whether clang gives bogus warnings for -Wdouble-promotion], - [lv_cv_clang_double_promotion_broken], [ - save_CFLAGS="$CFLAGS" - CFLAGS="-O2 -Wdouble-promotion -Werror" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ - #include - ]], [[ - float f = 0.0; - return isnan(f);]])], - [lv_cv_clang_double_promotion_broken=no], - [lv_cv_clang_double_promotion_broken=yes]) - CFLAGS="$save_CFLAGS"]) - - if test "$lv_cv_clang_double_promotion_broken" = "yes"; - then - dontwarn="$dontwarn -Wdouble-promotion" - fi - - # Clang complains about unused static inline functions - # which are common with G_DEFINE_AUTOPTR_CLEANUP_FUNC - AC_CACHE_CHECK([whether clang gives bogus warnings for -Wunused-function], - [lv_cv_clang_unused_function_broken], [ - save_CFLAGS="$CFLAGS" - CFLAGS="-Wunused-function -Werror" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ - static inline void foo(void) {} - ]], [[ - return 0]])], - [lv_cv_clang_unused_function_broken=no], - [lv_cv_clang_unused_function_broken=yes]) - CFLAGS="$save_CFLAGS"]) - - # We might fundamentally need some of these disabled forever, but - # ideally we'd turn many of them on - dontwarn="$dontwarn -Wfloat-equal" - dontwarn="$dontwarn -Wdeclaration-after-statement" - dontwarn="$dontwarn -Wpacked" - dontwarn="$dontwarn -Wunused-macros" - dontwarn="$dontwarn -Woverlength-strings" - dontwarn="$dontwarn -Wstack-protector" - dontwarn="$dontwarn -Wsuggest-attribute=malloc" - - # Get all possible GCC warnings - gl_MANYWARN_ALL_GCC([maybewarn]) - - # Remove the ones we don't want, blacklisted earlier - gl_MANYWARN_COMPLEMENT([wantwarn], [$maybewarn], [$dontwarn]) - - # -Wunused-functin is implied by -Wall we must turn it - # off explicitly. - if test "$lv_cv_clang_unused_function_broken" = "yes"; - then - wantwarn="$wantwarn -Wno-unused-function" - fi - - # manywarnings uses '-W' (aka -Wextra) which includes a bunch of stuff. - # Unfortunately, this means you can't simply use '-Wsign-compare' - # with gl_MANYWARN_COMPLEMENT - # So we have -W enabled, and then have to explicitly turn off... - wantwarn="$wantwarn -Wno-sign-compare" - # We do "bad" function casts all the time for event callbacks - wantwarn="$wantwarn -Wno-cast-function-type" - - # CLang incorrectly complains about dup typedefs win gnu99 mode - # so use this CLang-specific arg to keep it quiet - wantwarn="$wantwarn -Wno-typedef-redefinition" - - # manywarnings expects this to be part of -Wc++-compat, but we turn - # that one off, so we need to manually enable this again - wantwarn="$wantwarn -Wjump-misses-init" - - # manywarnings explicitly filters it out, preferring -Wswitch - # but that doesn't report missing enums if a default: - # is present. - wantwarn="$wantwarn -Wswitch-enum" - - # manywarnings turns on -Wformat=2 which implies -Wformat-nonliteral, - # so we need to manually re-exclude it. - wantwarn="$wantwarn -Wno-format-nonliteral" - - # -Wformat enables this by default, and we should keep it, - # but need to rewrite various areas of code first - wantwarn="$wantwarn -Wno-format-truncation" - - # This should be < 256 really. Currently we're down to 4096, - # but using 1024 bytes sized buffers (mostly for virStrerror) - # stops us from going down further - wantwarn="$wantwarn -Wframe-larger-than=4096" - gl_WARN_ADD([-Wframe-larger-than=262144], [RELAXED_FRAME_LIMIT_CFLAGS]) - - # Extra special flags - case $host in - aarch64-*-*) - dnl "error: -fstack-protector not supported for this target [-Werror]" - ;; - *-*-linux* | *-*-mingw*) - dnl Prefer -fstack-protector-strong if it's available. - dnl There doesn't seem to be great overhead in adding - dnl -fstack-protector-all instead of -fstack-protector. - dnl - dnl We also don't need ssp-buffer-size with -all or -strong, - dnl since functions are protected regardless of buffer size. - dnl wantwarn="$wantwarn --param=ssp-buffer-size=4" - wantwarn="$wantwarn -fstack-protector-strong" - ;; - *-*-freebsd*) - dnl FreeBSD ships old gcc 4.2.1 which doesn't handle - dnl -fstack-protector-all well - wantwarn="$wantwarn -fstack-protector" - - wantwarn="$wantwarn -Wno-unused-command-line-argument" - ;; - esac - wantwarn="$wantwarn -fexceptions" - wantwarn="$wantwarn -fasynchronous-unwind-tables" - - # Need -fipa-pure-const in order to make -Wsuggest-attribute=pure - # fire even without -O. - wantwarn="$wantwarn -fipa-pure-const" - # We should eventually enable this, but right now there are at - # least 75 functions triggering warnings. - wantwarn="$wantwarn -Wno-suggest-attribute=pure" - wantwarn="$wantwarn -Wno-suggest-attribute=const" - - if test "$enable_werror" = "yes" - then - wantwarn="$wantwarn -Werror" - fi - - # Request the gnu99 standard which is the best choice with - # gcc 4.8.0. Not a warning flag, but the probing mechanism - # is convenient - wantwarn="$wantwarn -std=gnu99" - - # Check for $CC support of each warning - for w in $wantwarn; do - gl_WARN_ADD([$w]) - done - - case $host in - *-*-linux*) - dnl Fall back to -fstack-protector-all if -strong is not available - case $WARN_CFLAGS in - *-fstack-protector-strong*) - ;; - *) - gl_WARN_ADD([-fstack-protector-all]) - ;; - esac - ;; - esac - - case $WARN_CFLAGS in - *-Wsuggest-attribute=format*) - AC_DEFINE([HAVE_SUGGEST_ATTRIBUTE_FORMAT], [1], [Whether -Wsuggest-attribute=format works]) - ;; - esac - - # Use security checked glibc headers - AH_VERBATIM([FORTIFY_SOURCE], - [/* Enable compile-time and run-time bounds-checking, and some warnings, - without upsetting newer glibc. */ - #if !defined _FORTIFY_SOURCE && defined __OPTIMIZE__ && __OPTIMIZE__ - # define _FORTIFY_SOURCE 2 - #endif - ]) - - if test "$gl_cv_warn_c__Wlogical_op" = yes && - test "$lv_cv_gcc_wlogical_op_equal_expr_broken" = yes; then - AC_DEFINE_UNQUOTED([BROKEN_GCC_WLOGICALOP_EQUAL_EXPR], 1, - [Define to 1 if gcc -Wlogical-op reports false positive 'or' equal expr]) - fi -]) diff --git a/m4/virt-warnings.m4 b/m4/virt-warnings.m4 deleted file mode 100644 index d272365f0a..0000000000 --- a/m4/virt-warnings.m4 +++ /dev/null @@ -1,115 +0,0 @@ -# warnings.m4 serial 14 -dnl Copyright (C) 2008-2020 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl From Simon Josefsson - -# gl_AS_VAR_APPEND(VAR, VALUE) -# ---------------------------- -# Provide the functionality of AS_VAR_APPEND if Autoconf does not have it. -m4_ifdef([AS_VAR_APPEND], -[m4_copy([AS_VAR_APPEND], [gl_AS_VAR_APPEND])], -[m4_define([gl_AS_VAR_APPEND], -[AS_VAR_SET([$1], [AS_VAR_GET([$1])$2])])]) - - -# gl_COMPILER_OPTION_IF(OPTION, [IF-SUPPORTED], [IF-NOT-SUPPORTED], -# [PROGRAM = AC_LANG_PROGRAM()]) -# ----------------------------------------------------------------- -# Check if the compiler supports OPTION when compiling PROGRAM. -# -# The effects of this macro depend on the current language (_AC_LANG). -AC_DEFUN([gl_COMPILER_OPTION_IF], -[ -dnl FIXME: gl_Warn must be used unquoted until we can assume Autoconf -dnl 2.64 or newer. -AS_VAR_PUSHDEF([gl_Warn], [gl_cv_warn_[]_AC_LANG_ABBREV[]_$1])dnl -AS_VAR_PUSHDEF([gl_Flags], [_AC_LANG_PREFIX[]FLAGS])dnl -AS_LITERAL_IF([$1], - [m4_pushdef([gl_Positive], m4_bpatsubst([$1], [^-Wno-], [-W]))], - [gl_positive="$1" -case $gl_positive in - -Wno-*) gl_positive=-W`expr "X$gl_positive" : 'X-Wno-\(.*\)'` ;; -esac -m4_pushdef([gl_Positive], [$gl_positive])])dnl -AC_CACHE_CHECK([whether _AC_LANG compiler handles $1], m4_defn([gl_Warn]), [ - gl_save_compiler_FLAGS="$gl_Flags" - gl_AS_VAR_APPEND(m4_defn([gl_Flags]), - [" $gl_unknown_warnings_are_errors ]m4_defn([gl_Positive])["]) - AC_LINK_IFELSE([m4_default([$4], [AC_LANG_PROGRAM([])])], - [AS_VAR_SET(gl_Warn, [yes])], - [AS_VAR_SET(gl_Warn, [no])]) - gl_Flags="$gl_save_compiler_FLAGS" -]) -AS_VAR_IF(gl_Warn, [yes], [$2], [$3]) -m4_popdef([gl_Positive])dnl -AS_VAR_POPDEF([gl_Flags])dnl -AS_VAR_POPDEF([gl_Warn])dnl -]) - -# gl_UNKNOWN_WARNINGS_ARE_ERRORS -# ------------------------------ -# Clang doesn't complain about unknown warning options unless one also -# specifies -Wunknown-warning-option -Werror. Detect this. -# -# The effects of this macro depend on the current language (_AC_LANG). -AC_DEFUN([gl_UNKNOWN_WARNINGS_ARE_ERRORS], -[_AC_LANG_DISPATCH([$0], _AC_LANG, $@)]) - -# Specialization for _AC_LANG = C. This macro can be AC_REQUIREd. -# Use of m4_defun rather than AC_DEFUN works around a bug in autoconf < 2.63b. -m4_defun([gl_UNKNOWN_WARNINGS_ARE_ERRORS(C)], -[ - AC_LANG_PUSH([C]) - gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL - AC_LANG_POP([C]) -]) - -# Specialization for _AC_LANG = C++. This macro can be AC_REQUIREd. -# Use of m4_defun rather than AC_DEFUN works around a bug in autoconf < 2.63b. -m4_defun([gl_UNKNOWN_WARNINGS_ARE_ERRORS(C++)], -[ - AC_LANG_PUSH([C++]) - gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL - AC_LANG_POP([C++]) -]) - -# Specialization for _AC_LANG = Objective C. This macro can be AC_REQUIREd. -# Use of m4_defun rather than AC_DEFUN works around a bug in autoconf < 2.63b. -m4_defun([gl_UNKNOWN_WARNINGS_ARE_ERRORS(Objective C)], -[ - AC_LANG_PUSH([Objective C]) - gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL - AC_LANG_POP([Objective C]) -]) - -AC_DEFUN([gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL], -[gl_COMPILER_OPTION_IF([-Werror -Wunknown-warning-option], - [gl_unknown_warnings_are_errors='-Wunknown-warning-option -Werror'], - [gl_unknown_warnings_are_errors=])]) - -# gl_WARN_ADD(OPTION, [VARIABLE = WARN_CFLAGS/WARN_CXXFLAGS], -# [PROGRAM = AC_LANG_PROGRAM()]) -# ----------------------------------------------------------- -# Adds parameter to WARN_CFLAGS/WARN_CXXFLAGS if the compiler supports it -# when compiling PROGRAM. For example, gl_WARN_ADD([-Wparentheses]). -# -# If VARIABLE is a variable name, AC_SUBST it. -# -# The effects of this macro depend on the current language (_AC_LANG). -AC_DEFUN([gl_WARN_ADD], -[AC_REQUIRE([gl_UNKNOWN_WARNINGS_ARE_ERRORS(]_AC_LANG[)]) -gl_COMPILER_OPTION_IF([$1], - [gl_AS_VAR_APPEND(m4_if([$2], [], [[WARN_]_AC_LANG_PREFIX[FLAGS]], [[$2]]), [" $1"])], - [], - [$3]) -m4_ifval([$2], - [AS_LITERAL_IF([$2], [AC_SUBST([$2])])], - [AC_SUBST([WARN_]_AC_LANG_PREFIX[FLAGS])])dnl -]) - -# Local Variables: -# mode: autoconf -# End: diff --git a/meson.build b/meson.build index 1ab0220815..28136dc397 100644 --- a/meson.build +++ b/meson.build @@ -7,6 +7,7 @@ project( 'buildtype=debugoptimized', 'b_pie=true', 'c_std=gnu99', + 'warning_level=2', ], ) @@ -208,18 +209,22 @@ libvirt_lib_version = '@0@.@1@.@2@'.format(libvirt_so_version, libvirt_age, libv # check compile flags cc = meson.get_compiler('c') +cc_flags = [] -cc_flags = [ +git_werror = get_option('git_werror') +if git_werror.enabled() or git_werror.auto() and git + cc_flags += [ '-Werror' ] +endif + +cc_flags += [ '-fno-common', '-W', '-Wabsolute-value', '-Waddress', '-Waddress-of-packed-member', '-Waggressive-loop-optimizations', - '-Wall', '-Wattribute-warning', '-Wattributes', - '-Wbad-function-cast', '-Wbool-compare', '-Wbool-operation', '-Wbuiltin-declaration-mismatch', @@ -236,27 +241,20 @@ cc_flags = [ '-Wcpp', '-Wdangling-else', '-Wdate-time', - '-Wdeprecated', '-Wdeprecated-declarations', '-Wdesignated-init', - '-Wdisabled-optimization', '-Wdiscarded-array-qualifiers', '-Wdiscarded-qualifiers', '-Wdiv-by-zero', - '-Wdouble-promotion', - '-Wduplicated-branches', '-Wduplicated-cond', '-Wduplicate-decl-specifier', '-Wempty-body', '-Wendif-labels', - '-Wenum-compare', '-Wexpansion-to-defined', - '-Wextra', '-Wformat-contains-nul', '-Wformat-extra-args', '-Wformat-nonliteral', '-Wformat-security', - '-Wformat-signedness', '-Wformat-y2k', '-Wformat-zero-length', '-Wframe-address', @@ -303,9 +301,7 @@ cc_flags = [ '-Wold-style-definition', '-Wopenmp-simd', '-Woverflow', - '-Woverlength-strings', '-Woverride-init', - '-Wpacked', '-Wpacked-bitfield-compat', '-Wpacked-not-aligned', '-Wparentheses', @@ -327,15 +323,12 @@ cc_flags = [ '-Wsizeof-array-argument', '-Wsizeof-pointer-div', '-Wsizeof-pointer-memaccess', - '-Wstack-protector', '-Wstrict-aliasing', - '-Wstrict-overflow', '-Wstrict-prototypes', '-Wstringop-truncation', '-Wsuggest-attribute=cold', '-Wsuggest-attribute=const', '-Wsuggest-attribute=format', - '-Wsuggest-attribute=malloc', '-Wsuggest-attribute=noreturn', '-Wsuggest-attribute=pure', '-Wsuggest-final-methods', @@ -344,21 +337,18 @@ cc_flags = [ '-Wswitch-bool', '-Wswitch-unreachable', '-Wsync-nand', - '-Wsystem-headers', '-Wtautological-compare', '-Wtrampolines', '-Wtrigraphs', '-Wtype-limits', '-Wuninitialized', '-Wunknown-pragmas', - '-Wunsafe-loop-optimizations', '-Wunused', '-Wunused-but-set-parameter', '-Wunused-but-set-variable', '-Wunused-function', '-Wunused-label', '-Wunused-local-typedefs', - '-Wunused-macros', '-Wunused-parameter', '-Wunused-result', '-Wunused-value', @@ -396,6 +386,206 @@ cc_flags += [ '-Wvla-larger-then=4031', ] +cc_flags += [ + # So we have -W enabled, and then have to explicitly turn off... + '-Wno-sign-compare', + + # We do "bad" function casts all the time for event callbacks + '-Wno-cast-function-type', + + # CLang incorrectly complains about dup typedefs win gnu99 mode + # so use this CLang-specific arg to keep it quiet + '-Wno-typedef-redefinition', + + # We don't use -Wc++-compat so we have to enable it explicitly + '-Wjump-misses-init', + + # -Wswitch is enabled but that doesn't report missing enums if a default: + # is present + '-Wswitch-enum', + + # -Wformat=2 implies -Wformat-nonliteral so we need to manually exclude it + '-Wno-format-nonliteral', + + # -Wformat enables this by default, and we should keep it, + # but need to rewrite various areas of code first + '-Wno-format-truncation', + + # This should be < 256 really. Currently we're down to 4096, + # but using 1024 bytes sized buffers (mostly for virStrerror) + # stops us from going down further + '-Wframe-larger-than=4096', + + # extra special flags + '-fexceptions', + '-fasynchronous-unwind-tables', + + # Need -fipa-pure-const in order to make -Wsuggest-attribute=pure + # fire even without -O. + '-fipa-pure-const', + + # We should eventually enable this, but right now there are at + # least 75 functions triggering warnings. + '-Wno-suggest-attribute=pure', + '-Wno-suggest-attribute=const', +] + +# on aarch64 error: -fstack-protector not supported for this target +if host_machine.cpu_family() != 'aarch64' + if host_machine.system() in [ 'linux', 'freebsd', 'windows' ] + # we prefer -fstack-protector-strong but fallback to -fstack-protector-all + fstack_cflags = cc.first_supported_argument([ + '-fstack-protector-strong', + '-fstack-protector-all', + ]) + cc_flags += fstack_cflags + + # When building with mingw using -fstack-protector requires libssp library + # which is included by using -fstack-protector with linker. + if fstack_cflags.length() == 1 and host_machine.system() == 'windows' + add_project_link_arguments(fstack_cflags, language: 'c') + endif + endif +endif + +if cc.has_argument('-Wlogical-op') + # Broken in 6.0 and later + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69602 + w_logical_op_args = ['-O2', '-Wlogical-op', '-Werror'] + w_logical_op_code = ''' + #define TEST1 1 + #define TEST2 TEST1 + + int main(void) { + int test = 0; + return test == TEST1 || test == TEST2; + } + ''' + if not cc.compiles(w_logical_op_code, args: w_logical_op_args) + conf.set('BROKEN_GCC_WLOGICALOP_EQUAL_EXPR', 1) + endif +endif + +# Check whether clang gives bogus warning for -Wdouble-promotion. +w_double_promotion_args = ['-O2', '-Wdouble-promotion', '-Werror'] +w_double_promotion_code = ''' + #include + + int main(void) { + float f = 0.0; + return isnan(f); + } +''' +if cc.compiles(w_double_promotion_code, args: w_double_promotion_args, name: '-Wdouble-promotion') + cc_flags += ['-Wdouble-promotion'] +endif + +# Clang complains about unused static inline functions which are common +# with G_DEFINE_AUTOPTR_CLEANUP_FUNC. +w_unused_function_args = ['-Wunused-function', '-Werror'] +w_unused_function_code = ''' + static inline void foo(void) {} + + int main(void) { return 0; } +''' +# -Wunused-function is implied by -Wall, we must turn it off explicitly. +if not cc.compiles(w_unused_function_code, args: w_unused_function_args) + cc_flags += ['-Wno-unused-function'] +endif + +cc_flags_disabled = [ + # In meson this is specified using 'c_std=gnu99' in project() function. + '-std=gnu99', + + # In meson this is specified using 'warning_level=2' in project() function. + '-Wall', + '-Wextra', + + # don't care about C++ compiler compat + '-Wc++-compat', + '-Wabi', + '-Wdeprecated', + + # Don't care about ancient C standard compat + '-Wtraditional', + '-Wtraditional-conversion', + + # Ignore warnings in /usr/include + '-Wsystem-headers', + + # Happy for compiler to add struct padding + '-Wpadded', + + # GCC very confused with -O2 + '-Wunreachable-code', + + # Too many to deal with + '-Wconversion', + '-Wsign-conversion', + + # Need to allow bad cast for execve() + '-Wcast-qual', + + # We need to use long long in many places + '-Wlong-long', + + # We allow manual list of all enum cases without default + '-Wswitch-default', + + # Not a problem since we don't use -fstrict-overflow + '-Wstrict-overflow', + + # Not a problem since we don't use -funsafe-loop-optimizations + '-Wunsafe-loop-optimizations', + + # gcc 4.4.6 complains this is C++ only; gcc 4.7.0 implies this from -Wall + '-Wenum-compare', + + # gcc 5.1 -Wformat-signedness mishandles enums, not ready for prime time + '-Wformat-signedness', + + # Several conditionals expand the same on both branches depending on the + # particular platform/architecture + '-Wduplicated-branches', + + # > This warning does not generally indicate that there is anything wrong + # > with your code; it merely indicates that GCC's optimizers are unable + # > to handle the code effectively. + # Source: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html + '-Wdisabled-optimization', + + # Various valid glib APIs/macros trigger this warning + '-Wbad-function-cast', + + # We might fundamentally need some of these disabled forever, but + # ideally we'd turn many of them on + '-Wfloat-equal', + '-Wdeclaration-after-statement', + '-Wpacked', + '-Wunused-macros', + '-Woverlength-strings', + '-Wstack-protector', + '-Wsuggest-attribute=malloc', +] + +foreach flag : cc_flags_disabled + if cc_flags.contains(flag) + error('@0@ is disabled but listed in cc_flags'.format(flag)) + endif +endforeach + +supported_cc_flags = cc.get_supported_arguments(cc_flags) +add_project_arguments(supported_cc_flags, language: 'c') + +if cc.has_argument('-Wsuggest-attribute=format') + conf.set('HAVE_SUGGEST_ATTRIBUTE_FORMAT', 1) +endif + +# used in tests +cc_flags_relaxed_frame_limit = [ + '-Wframe-larger-than=262144', +] + # define top include directory @@ -412,3 +602,9 @@ test_summary = { 'Coverage': coverage_flags.length() > 0, } summary(test_summary, section: 'Test suite', bool_yn: true) + +misc_summary = { + 'Use -Werror': cc_flags.contains('-Werror'), + 'Warning Flags': supported_cc_flags, +} +summary(misc_summary, section: 'Miscellaneous', bool_yn: true, list_sep: ' ') diff --git a/meson_options.txt b/meson_options.txt index 7171d4c17b..d5e723cd88 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -6,3 +6,4 @@ option('system', type: 'boolean', value: false, description: 'Set install paths option('runstatedir', type: 'string', value: '', description: 'State directory for temporary sockets, pid files, etc') option('expensive_tests', type: 'feature', value: 'auto', description: 'set the default for enabling expensive tests (long timeouts), use VIR_TEST_EXPENSIVE to override') option('test_coverage', type: 'boolean', value: false, description: 'turn on code coverage instrumentation') +option('git_werror', type: 'feature', value: 'auto', description: 'use -Werror if building from GIT')