Browse Source

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
Nick Mathewson 7 years ago
parent
commit
9bbd6502f0

+ 4 - 0
changes/bug19216

@@ -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.

+ 57 - 118
configure.ac

@@ -1656,59 +1656,12 @@ esac
 
 # Add some more warnings which we use in development but not in the
 # 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
 
-  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
     *-*-openbsd* | *-*-bitrig*)
       # 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" ;;
   esac
 
+
   CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith"
   CFLAGS="$CFLAGS -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings"
   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 -Waggregate-return -Wpacked -Wunused"
   CFLAGS="$CFLAGS -Wunused-parameter"
 
-  if test "x$have_gcc4" = "xyes"; then
-    # These warnings break gcc 3.3.5 and work on gcc 4.0.2
-    CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wold-style-definition"
-  fi
-
-  if test "x$have_gcc42" = "xyes"; then
-    # These warnings break gcc 4.0.2 and work on gcc 4.2
-    # XXXX020 See if any of these work with earlier versions.
-    CFLAGS="$CFLAGS -Waddress -Wmissing-noreturn"
-  fi
-
-  if test "x$have_gcc42" = "xyes" && test "x$have_gcc5" != "xyes"; then
-    CFLAGS="$CFLAGS -Wstrict-overflow=1"
-    # We used to use -Wstrict-overflow=5, but that breaks us heavily under 4.3.
-    # Save it for GCC 5 where they improved the testing.
-  fi
-
-  if test "x$have_gcc42" = "xyes" && test "x$have_clang" = "xno"; then
-    # These warnings break gcc 4.0.2 and clang, but work on gcc 4.2
-    CFLAGS="$CFLAGS -Wnormalized=id -Woverride-init"
-  fi
-
-  if test "x$have_gcc43" = "xyes"; then
-    # 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"
+  # GCC4.3 users once report trouble with -Wstrict-overflow=5.  GCC5 users
+  # have it work better.
+  # CFLAGS="$CFLAGS -Wstrict-overflow=1"
+
+  # 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"
+
+  m4_foreach_w([warning_flag], [
+     -Waddress
+     -Warray-bounds
+     -Wc99-c11-compat
+     -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 "$tor_cv_cflags__Wnull_dereference" = "yes"; then
+    AC_DEFINE([HAVE_CFLAG_WNULL_DEREFERENCE], 1, [True if we have -Wnull-dereference])
   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"
+  if test "$tor_cv_cflags__Woverlength_strings" = "yes"; then
+    AC_DEFINE([HAVE_CFLAG_WOVERLENGTH_STRINGS], 1, [True if we have -Woverlength-strings])
   fi
 
   if test "x$enable_fatal_warnings" = "xyes"; then
@@ -1799,8 +1740,6 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
     CFLAGS="$CFLAGS -Werror"
   fi
 
-##This will break the world on some 64-bit architectures
-# CFLAGS="$CFLAGS -Winline"
 fi
 
 if test "$enable_coverage" = "yes" && test "$have_clang" = "no"; then

+ 1 - 1
src/common/torlog.h

@@ -176,7 +176,7 @@ void log_fn_ratelim_(struct ratelim_t *ratelim, int severity,
                      const char *format, ...)
   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
  * break. */

+ 0 - 4
src/common/tortls.c

@@ -26,11 +26,9 @@
 
 #include "compat.h"
 
-#if GCC_VERSION >= 402
 /* 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. */
 DISABLE_GCC_WARNING(redundant-decls)
-#endif
 
 #include <openssl/opensslv.h>
 #include "crypto.h"
@@ -48,9 +46,7 @@ DISABLE_GCC_WARNING(redundant-decls)
 #include <openssl/bn.h>
 #include <openssl/rsa.h>
 
-#if GCC_VERSION >= 402
 ENABLE_GCC_WARNING(redundant-decls)
-#endif
 
 #ifdef USE_BUFFEREVENTS
 #include <event2/bufferevent_ssl.h>

+ 9 - 0
src/ext/ed25519/donna/ed25519-donna-64bit-x86.h

@@ -2,6 +2,11 @@
 
 #define HAVE_GE25519_SCALARMULT_BASE_CHOOSE_NIELS
 
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Woverlength-strings"
+#endif
+
 DONNA_NOINLINE static void
 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;
@@ -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) */
 

+ 1 - 1
src/or/config.c

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

+ 2 - 2
src/test/test_bt_cl.c

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

+ 2 - 2
src/test/test_dir_handle_get.c

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

+ 2 - 2
src/test/test_helpers.c

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

+ 2 - 2
src/test/test_microdesc.c

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