Use autoconf, not gcc version, to decide which warnings we have

This gives more accurate results under Clang, which can only help us
detect more warnings in more places.

Fixes bug 19216; bugfix on 0.2.0.1-alpha
This commit is contained in:
Nick Mathewson 2016-06-01 13:38:36 -04:00
parent ad16c55286
commit 9bbd6502f0
10 changed files with 77 additions and 129 deletions

4
changes/bug19216 Normal file
View File

@ -0,0 +1,4 @@
o Minor bugfixes:
- When building with Clang, include our full array of GCC warnings.
(Previously, we included only a subset, because of the way we
detected them.) Fixes bug 19216; bugfix on 0.2.0.1-alpha.

View File

@ -1656,59 +1656,12 @@ esac
# Add some more warnings which we use in development but not in the # Add some more warnings which we use in development but not in the
# released versions. (Some relevant gcc versions can't handle these.) # released versions. (Some relevant gcc versions can't handle these.)
#
# Note that we have to do this near the end of the autoconf process, or
# else we may run into problems when these warnings hit on the testing C
# programs that autoconf wants to build.
if test "x$enable_gcc_warnings_advisory" != "xno"; then if test "x$enable_gcc_warnings_advisory" != "xno"; then
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
#if !defined(__GNUC__) || (__GNUC__ < 4)
#error
#endif])], have_gcc4=yes, have_gcc4=no)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
#if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
#error
#endif])], have_gcc42=yes, have_gcc42=no)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
#if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
#error
#endif])], have_gcc43=yes, have_gcc43=no)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
#if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)
#error
#endif])], have_gcc46=yes, have_gcc46=no)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
#if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 7)
#error
#endif])], have_gcc47=yes, have_gcc47=no)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
#if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 8)
#error
#endif])], have_gcc48=yes, have_gcc48=no)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
#if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 9)
#error
#endif])], have_gcc49=yes, have_gcc49=no)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
#if !defined(__GNUC__) || (__GNUC__ < 5)
#error
#endif])], have_gcc5=yes, have_gcc5=no)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
#if !defined(__GNUC__) || (__GNUC__ < 6)
#error
#endif])], have_gcc6=yes, have_gcc6=no)
save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -Wshorten-64-to-32"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], have_shorten64_flag=yes,
have_shorten64_flag=no)
CFLAGS="$save_CFLAGS"
case "$host" in case "$host" in
*-*-openbsd* | *-*-bitrig*) *-*-openbsd* | *-*-bitrig*)
# Some OpenBSD versions (like 4.8) have -Wsystem-headers by default. # Some OpenBSD versions (like 4.8) have -Wsystem-headers by default.
@ -1718,79 +1671,67 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
CFLAGS="$CFLAGS -Wno-system-headers" ;; CFLAGS="$CFLAGS -Wno-system-headers" ;;
esac esac
CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith" CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith"
CFLAGS="$CFLAGS -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings" CFLAGS="$CFLAGS -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings"
CFLAGS="$CFLAGS -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2" CFLAGS="$CFLAGS -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2"
CFLAGS="$CFLAGS -Wwrite-strings -Wmissing-declarations -Wredundant-decls" CFLAGS="$CFLAGS -Wwrite-strings -Wmissing-declarations"
CFLAGS="$CFLAGS -Wnested-externs -Wbad-function-cast -Wswitch-enum" CFLAGS="$CFLAGS -Wnested-externs -Wbad-function-cast -Wswitch-enum"
CFLAGS="$CFLAGS -Waggregate-return -Wpacked -Wunused" CFLAGS="$CFLAGS -Waggregate-return -Wpacked -Wunused"
CFLAGS="$CFLAGS -Wunused-parameter" CFLAGS="$CFLAGS -Wunused-parameter"
if test "x$have_gcc4" = "xyes"; then # GCC4.3 users once report trouble with -Wstrict-overflow=5. GCC5 users
# These warnings break gcc 3.3.5 and work on gcc 4.0.2 # have it work better.
CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wold-style-definition" # CFLAGS="$CFLAGS -Wstrict-overflow=1"
fi
if test "x$have_gcc42" = "xyes"; then # This warning was added in gcc 4.3, but it appears to generate
# These warnings break gcc 4.0.2 and work on gcc 4.2 # spurious warnings in gcc 4.4. I don't know if it works in 4.5.
# XXXX020 See if any of these work with earlier versions. #CFLAGS="$CFLAGS -Wlogical-op"
CFLAGS="$CFLAGS -Waddress -Wmissing-noreturn"
fi
if test "x$have_gcc42" = "xyes" && test "x$have_gcc5" != "xyes"; then m4_foreach_w([warning_flag], [
CFLAGS="$CFLAGS -Wstrict-overflow=1" -Waddress
# We used to use -Wstrict-overflow=5, but that breaks us heavily under 4.3. -Warray-bounds
# Save it for GCC 5 where they improved the testing. -Wc99-c11-compat
fi -Wdate-time
-Wdouble-promotion
-Wduplicated-cond
-Wextra
-Wfloat-conversion
-Wignored-attributes
-Winit-self
-Wlogical-op
-Wmissing-field-initializers
-Wmissing-format-attribute
-Wmissing-noreturn
-Wnormalized=id
-Wnull-dereference
-Wold-style-definition
-Woverlength-strings
-Woverride-init
-Wshift-count-negative
-Wshift-count-overflow
-Wshift-negative-value
-Wshift-overflow=2
-Wshorten-64-to-32
-Wsizeof-array-argument
-Wstrict-overflow=2
-Wsuggest-attribute=format
-Wsuggest-attribute=noreturn
-Wswitch-bool
-Wsync-nand
-Wtrampolines
-Wunused-but-set-parameter
-Wunused-but-set-variable
-Wunused-const-variable=2
-Wunused-local-typedefs
-Wvariadic-macros
], [ TOR_CHECK_CFLAGS([warning_flag]) ])
if test "x$have_gcc42" = "xyes" && test "x$have_clang" = "xno"; then if test "$tor_cv_cflags__Wnull_dereference" = "yes"; then
# These warnings break gcc 4.0.2 and clang, but work on gcc 4.2 AC_DEFINE([HAVE_CFLAG_WNULL_DEREFERENCE], 1, [True if we have -Wnull-dereference])
CFLAGS="$CFLAGS -Wnormalized=id -Woverride-init"
fi fi
if test "$tor_cv_cflags__Woverlength_strings" = "yes"; then
if test "x$have_gcc43" = "xyes"; then AC_DEFINE([HAVE_CFLAG_WOVERLENGTH_STRINGS], 1, [True if we have -Woverlength-strings])
# These warnings break gcc 4.2 and work on gcc 4.3
# XXXX020 See if any of these work with earlier versions.
CFLAGS="$CFLAGS -Wextra -Warray-bounds"
fi
if test "x$have_gcc46" = "xyes"; then
# This warning was added in gcc 4.3, but it appears to generate
# spurious warnings in gcc 4.4. I don't know if it works in 4.5.
CFLAGS="$CFLAGS -Wlogical-op"
# and these should be just fine in gcc 4.6
CFLAGS="$CFLAGS -Wmissing-format-attribute -Wsuggest-attribute=noreturn -Wsync-nand -Wtrampolines -Wunused-but-set-parameter -Wunused-but-set-variable -Wvariadic-macros"
CFLAGS="$CFLAGS -Wdouble-promotion"
CFLAGS="$CFLAGS -Woverlength-strings"
fi
if test "x$have_gcc47" = "xyes"; then
CFLAGS="$CFLAGS -Wunused-local-typedefs"
fi
if test "x$have_gcc48" = "xyes"; then
CFLAGS="$CFLAGS -Wsuggest-attribute=format"
fi
if test "x$have_gcc49" = "xyes"; then
CFLAGS="$CFLAGS -Wdate-time"
CFLAGS="$CFLAGS -Wfloat-conversion"
fi
if test "x$have_gcc5" = "xyes"; then
CFLAGS="$CFLAGS -Wc99-c11-compat -Wshift-count-negative -Wshift-count-overflow -Wsizeof-array-argument -Wswitch-bool"
CFLAGS="$CFLAGS -Wstrict-overflow=2"
fi
if test "x$have_gcc6" = "xyes"; then
CFLAGS="$CFLAGS -Wignored-attributes -Wshift-negative-value -Wshift-overflow=2"
CFLAGS="$CFLAGS -Wnull-dereference"
CFLAGS="$CFLAGS -Wduplicated-cond"
CFLAGS="$CFLAGS -Wunused-const-variable=2"
fi
if test "x$have_shorten64_flag" = "xyes"; then
CFLAGS="$CFLAGS -Wshorten-64-to-32"
fi fi
if test "x$enable_fatal_warnings" = "xyes"; then if test "x$enable_fatal_warnings" = "xyes"; then
@ -1799,8 +1740,6 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
CFLAGS="$CFLAGS -Werror" CFLAGS="$CFLAGS -Werror"
fi fi
##This will break the world on some 64-bit architectures
# CFLAGS="$CFLAGS -Winline"
fi fi
if test "$enable_coverage" = "yes" && test "$have_clang" = "no"; then if test "$enable_coverage" = "yes" && test "$have_clang" = "no"; then

View File

@ -176,7 +176,7 @@ void log_fn_ratelim_(struct ratelim_t *ratelim, int severity,
const char *format, ...) const char *format, ...)
CHECK_PRINTF(5,6); CHECK_PRINTF(5,6);
#if defined(__GNUC__) #if defined(__GNUC__) && __GNUC__ <= 3
/* These are the GCC varidaic macros, so that older versions of GCC don't /* These are the GCC varidaic macros, so that older versions of GCC don't
* break. */ * break. */

View File

@ -26,11 +26,9 @@
#include "compat.h" #include "compat.h"
#if GCC_VERSION >= 402
/* Some versions of OpenSSL declare SSL_get_selected_srtp_profile twice in /* Some versions of OpenSSL declare SSL_get_selected_srtp_profile twice in
* srtp.h. Suppress the GCC warning so we can build with -Wredundant-decl. */ * srtp.h. Suppress the GCC warning so we can build with -Wredundant-decl. */
DISABLE_GCC_WARNING(redundant-decls) DISABLE_GCC_WARNING(redundant-decls)
#endif
#include <openssl/opensslv.h> #include <openssl/opensslv.h>
#include "crypto.h" #include "crypto.h"
@ -48,9 +46,7 @@ DISABLE_GCC_WARNING(redundant-decls)
#include <openssl/bn.h> #include <openssl/bn.h>
#include <openssl/rsa.h> #include <openssl/rsa.h>
#if GCC_VERSION >= 402
ENABLE_GCC_WARNING(redundant-decls) ENABLE_GCC_WARNING(redundant-decls)
#endif
#ifdef USE_BUFFEREVENTS #ifdef USE_BUFFEREVENTS
#include <event2/bufferevent_ssl.h> #include <event2/bufferevent_ssl.h>

View File

@ -2,6 +2,11 @@
#define HAVE_GE25519_SCALARMULT_BASE_CHOOSE_NIELS #define HAVE_GE25519_SCALARMULT_BASE_CHOOSE_NIELS
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Woverlength-strings"
#endif
DONNA_NOINLINE static void DONNA_NOINLINE static void
ge25519_scalarmult_base_choose_niels(ge25519_niels *t, const uint8_t table[256][96], uint32_t pos, signed char b) { ge25519_scalarmult_base_choose_niels(ge25519_niels *t, const uint8_t table[256][96], uint32_t pos, signed char b) {
int64_t breg = (int64_t)b; int64_t breg = (int64_t)b;
@ -347,5 +352,9 @@ ge25519_scalarmult_base_choose_niels(ge25519_niels *t, const uint8_t table[256][
); );
} }
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif /* defined(ED25519_GCC_64BIT_X86_CHOOSE) */ #endif /* defined(ED25519_GCC_64BIT_X86_CHOOSE) */

View File

@ -2683,7 +2683,7 @@ options_validate_cb(void *old_options, void *options, void *default_options,
#define REJECT(arg) \ #define REJECT(arg) \
STMT_BEGIN *msg = tor_strdup(arg); return -1; STMT_END STMT_BEGIN *msg = tor_strdup(arg); return -1; STMT_END
#ifdef __GNUC__ #if defined(__GNUC__) && __GNUC__ <= 3
#define COMPLAIN(args...) \ #define COMPLAIN(args...) \
STMT_BEGIN log_warn(LD_CONFIG, args); STMT_END STMT_BEGIN log_warn(LD_CONFIG, args); STMT_END
#else #else

View File

@ -28,7 +28,7 @@ int a_tangled_web(int x) NOINLINE;
int we_weave(int x) NOINLINE; int we_weave(int x) NOINLINE;
static void abort_handler(int s) NORETURN; static void abort_handler(int s) NORETURN;
#if GCC_VERSION >= 601 #ifdef HAVE_CFLAG_WNULL_DEREFERENCE
DISABLE_GCC_WARNING(null-dereference) DISABLE_GCC_WARNING(null-dereference)
#endif #endif
int int
@ -50,7 +50,7 @@ crash(int x)
crashtype *= x; crashtype *= x;
return crashtype; return crashtype;
} }
#if GCC_VERSION >= 601 #ifdef HAVE_CFLAG_WNULL_DEREFERENCE
ENABLE_GCC_WARNING(null-dereference) ENABLE_GCC_WARNING(null-dereference)
#endif #endif

View File

@ -38,13 +38,13 @@
#include <dirent.h> #include <dirent.h>
#endif #endif
#if GCC_VERSION >= 406 #ifdef HAVE_CFLAG_WOVERLENGTH_STRINGS
DISABLE_GCC_WARNING(overlength-strings) DISABLE_GCC_WARNING(overlength-strings)
/* We allow huge string constants in the unit tests, but not in the code /* We allow huge string constants in the unit tests, but not in the code
* at large. */ * at large. */
#endif #endif
#include "vote_descriptors.inc" #include "vote_descriptors.inc"
#if GCC_VERSION >= 406 #ifdef HAVE_CFLAG_WOVERLENGTH_STRINGS
ENABLE_GCC_WARNING(overlength-strings) ENABLE_GCC_WARNING(overlength-strings)
#endif #endif

View File

@ -16,13 +16,13 @@
#include "test.h" #include "test.h"
#include "test_helpers.h" #include "test_helpers.h"
#if GCC_VERSION >= 406 #ifdef HAVE_CFLAG_WOVERLENGTH_STRINGS
DISABLE_GCC_WARNING(overlength-strings) DISABLE_GCC_WARNING(overlength-strings)
/* We allow huge string constants in the unit tests, but not in the code /* We allow huge string constants in the unit tests, but not in the code
* at large. */ * at large. */
#endif #endif
#include "test_descriptors.inc" #include "test_descriptors.inc"
#if GCC_VERSION >= 406 #ifdef HAVE_CFLAG_WOVERLENGTH_STRINGS
ENABLE_GCC_WARNING(overlength-strings) ENABLE_GCC_WARNING(overlength-strings)
#endif #endif

View File

@ -490,7 +490,7 @@ test_md_generate(void *arg)
routerinfo_free(ri); routerinfo_free(ri);
} }
#if GCC_VERSION >= 406 #ifdef HAVE_CFLAG_WOVERLENGTH_STRINGS
DISABLE_GCC_WARNING(overlength-strings) DISABLE_GCC_WARNING(overlength-strings)
/* We allow huge string constants in the unit tests, but not in the code /* We allow huge string constants in the unit tests, but not in the code
* at large. */ * at large. */
@ -650,7 +650,7 @@ static const char MD_PARSE_TEST_DATA[] =
"id rsa1024 2A8wYpHxnkKJ92orocvIQBzeHlE\n" "id rsa1024 2A8wYpHxnkKJ92orocvIQBzeHlE\n"
"p6 allow 80\n" "p6 allow 80\n"
; ;
#if GCC_VERSION >= 406 #ifdef HAVE_CFLAG_WOVERLENGTH_STRINGS
ENABLE_GCC_WARNING(overlength-strings) ENABLE_GCC_WARNING(overlength-strings)
#endif #endif