From b8df54ffbefc5ddf40ddcda68a2a682769c5833d Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 9 Apr 2012 00:45:59 -0700 Subject: [PATCH] configure: new option --enable-gcc-warnings I have been using this change for many months in my private copy of Emacs, and have used it to find several bugs. It's mature enough to publish now. * Makefile.in (GNULIB_MODULES): Add warnings, manywarnings. * configure.in: Support --enable-gcc-warnings, in the style of other GNU packages such as coreutils. (C_WARNINGS_SWITCH): Remove, replacing with... (WARN_CFLAGS, GNULIB_WARN_CFLAGS): New variable. (PKG_CHECK_MODULES, C_SWITCH_X_SITE): Use -isystem rather than -I, when including system files with GCC. * etc/NEWS: Mention --enable-gcc-warnings. * lib/Makefile.am (AM_CFLAGS): New macro. * m4/manywarnings.m4, m4/warnings.m4: New files, from gnulib. * lib-src/Makefile.in (C_WARNINGS_SWITCH): Remove. (WARN_CFLAGS, WERROR_CFLAGS): New macros. (BASE_CFLAGS): Use new macros rather than old. * lwlib/Makefile.in (C_WARNINGS_SWITCH): Remove. (WARN_CFLAGS, WERROR_CFLAGS): New macros. (ALL_CFLAGS): Use new macros rather than old. * oldXMenu/Makefile.in (C_WARNINGS_SWITCH): Remove. (WARN_CFLAGS, WERROR_CFLAGS): New macros. (ALL_CFLAGS): Use new macros rather than old. * src/Makefile.in (C_WARNINGS_SWITCH): Remove. (WARN_CFLAGS, WERROR_CFLAGS): New macros. (ALL_CFLAGS): Use new macros rather than old. * src/process.c: Ignore -Wstrict-overflow to work around GCC bug 52904. * src/regex.c: Ignore -Wstrict-overflow. If !emacs, also ignore -Wunused-but-set-variable, -Wunused-function, -Wunused-macros, -Wunused-result, -Wunused-variable. This should go away once the Emacs and Gnulib regex code is merged. (xmalloc, xrealloc): Now static. --- ChangeLog | 17 ++++ Makefile.in | 5 +- configure.in | 167 ++++++++++++++++++++++++++++----------- etc/NEWS | 7 ++ lib-src/ChangeLog | 7 ++ lib-src/Makefile.in | 6 +- lib/Makefile.am | 1 + lwlib/ChangeLog | 7 ++ lwlib/Makefile.in | 6 +- m4/manywarnings.m4 | 184 +++++++++++++++++++++++++++++++++++++++++++ m4/warnings.m4 | 42 ++++++++++ oldXMenu/ChangeLog | 7 ++ oldXMenu/Makefile.in | 5 +- src/ChangeLog | 13 +++ src/Makefile.in | 5 +- src/process.c | 7 ++ src/regex.c | 17 +++- 17 files changed, 447 insertions(+), 56 deletions(-) create mode 100644 m4/manywarnings.m4 create mode 100644 m4/warnings.m4 diff --git a/ChangeLog b/ChangeLog index 2fe50a6d83..8f7ccc573a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2012-04-09 Paul Eggert + + configure: new option --enable-gcc-warnings + I have been using this change for many months in my private copy + of Emacs, and have used it to find several bugs. It's mature + enough to publish now. + * Makefile.in (GNULIB_MODULES): Add warnings, manywarnings. + * configure.in: Support --enable-gcc-warnings, in the style of + other GNU packages such as coreutils. + (C_WARNINGS_SWITCH): Remove, replacing with... + (WARN_CFLAGS, GNULIB_WARN_CFLAGS): New variable. + (PKG_CHECK_MODULES, C_SWITCH_X_SITE): Use -isystem rather than -I, + when including system files with GCC. + * etc/NEWS: Mention --enable-gcc-warnings. + * lib/Makefile.am (AM_CFLAGS): New macro. + * m4/manywarnings.m4, m4/warnings.m4: New files, from gnulib. + 2012-04-09 Glenn Morris * Makefile.in (leim): Check cd return value. Pass fewer variables. diff --git a/Makefile.in b/Makefile.in index 3ee5e8ae8e..2d54aa1f3a 100644 --- a/Makefile.in +++ b/Makefile.in @@ -336,8 +336,9 @@ GNULIB_MODULES = \ careadlinkat crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 dtoastr \ dup2 \ filemode getloadavg getopt-gnu ignore-value intprops lstat \ - mktime pthread_sigmask readlink \ - socklen stdarg stdio strftime strtoimax strtoumax symlink sys_stat + manywarnings mktime pthread_sigmask readlink \ + socklen stdarg stdio strftime strtoimax strtoumax symlink sys_stat \ + warnings GNULIB_TOOL_FLAGS = \ --avoid=msvc-inval --avoid=msvc-nothrow \ --avoid=raise --avoid=threadlib \ diff --git a/configure.in b/configure.in index 14a80622cd..4b67078bf3 100644 --- a/configure.in +++ b/configure.in @@ -686,47 +686,121 @@ else test "x$NON_GCC_TEST_OPTIONS" != x && CC="$CC $NON_GCC_TEST_OPTIONS" fi -### Use -Wdeclaration-after-statement if the compiler supports it -AC_MSG_CHECKING([whether gcc understands -Wdeclaration-after-statement]) -SAVE_CFLAGS="$CFLAGS" -CFLAGS="$CFLAGS -Wdeclaration-after-statement" -AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], has_option=yes, has_option=no) -if test $has_option = yes; then - C_WARNINGS_SWITCH="-Wdeclaration-after-statement $C_WARNINGS_SWITCH" -fi -AC_MSG_RESULT($has_option) -CFLAGS="$SAVE_CFLAGS" -unset has_option -unset SAVE_CFLAGS - -### Use -Wold-style-definition if the compiler supports it -# This can be removed when conversion to standard C is finished. -AC_MSG_CHECKING([whether gcc understands -Wold-style-definition]) -SAVE_CFLAGS="$CFLAGS" -CFLAGS="$CFLAGS -Wold-style-definition" -AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], has_option=yes, has_option=no) -if test $has_option = yes; then - C_WARNINGS_SWITCH="-Wold-style-definition $C_WARNINGS_SWITCH" -fi -AC_MSG_RESULT($has_option) -CFLAGS="$SAVE_CFLAGS" -unset has_option -unset SAVE_CFLAGS - -### Use -Wimplicit-function-declaration if the compiler supports it -AC_MSG_CHECKING([whether gcc understands -Wimplicit-function-declaration]) -SAVE_CFLAGS="$CFLAGS" -CFLAGS="$CFLAGS -Wimplicit-function-declaration" -AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], has_option=yes, has_option=no) -if test $has_option = yes; then - C_WARNINGS_SWITCH="-Wimplicit-function-declaration $C_WARNINGS_SWITCH" -fi -AC_MSG_RESULT($has_option) -CFLAGS="$SAVE_CFLAGS" -unset has_option -unset SAVE_CFLAGS - -AC_SUBST(C_WARNINGS_SWITCH) +AC_ARG_ENABLE([gcc-warnings], + [AS_HELP_STRING([--enable-gcc-warnings], + [turn on lots of GCC warnings (for developers)])], + [case $enableval in + yes|no) ;; + *) AC_MSG_ERROR([bad value $enableval for gcc-warnings option]) ;; + esac + gl_gcc_warnings=$enableval], + [gl_gcc_warnings=no] +) + +# gl_GCC_VERSION_IFELSE([major], [minor], [run-if-found], [run-if-not-found]) +# ------------------------------------------------ +# If $CPP is gcc-MAJOR.MINOR or newer, then run RUN-IF-FOUND. +# Otherwise, run RUN-IF-NOT-FOUND. +AC_DEFUN([gl_GCC_VERSION_IFELSE], + [AC_PREPROC_IFELSE( + [AC_LANG_PROGRAM( + [[ +#if ($1) < __GNUC__ || (($1) == __GNUC__ && ($2) <= __GNUC_MINOR__) +/* ok */ +#else +# error "your version of gcc is older than $1.$2" +#endif + ]]), + ], [$3], [$4]) + ] +) + +# When compiling with GCC, prefer -isystem to -I when including system +# include files, to avoid generating useless diagnostics for the files. +if test "$gl_gcc_warnings" != yes; then + isystem='-I' +else + isystem='-isystem ' + + # This, $nw, is the list of warnings we disable. + nw= + + case $with_x_toolkit in + lucid | athena | motif) + # Old toolkits mishandle 'const'. + nw="$nw -Wwrite-strings" + ;; + *) + gl_WARN_ADD([-Werror], [WERROR_CFLAGS]) + ;; + esac + AC_SUBST([WERROR_CFLAGS]) + + nw="$nw -Waggregate-return" # anachronistic + nw="$nw -Wlong-long" # C90 is anachronistic (lib/gethrxtime.h) + nw="$nw -Wc++-compat" # We don't care about C++ compilers + nw="$nw -Wundef" # Warns on '#if GNULIB_FOO' etc in gnulib + nw="$nw -Wtraditional" # Warns on #elif which we use often + nw="$nw -Wcast-qual" # Too many warnings for now + nw="$nw -Wconversion" # Too many warnings for now + nw="$nw -Wsystem-headers" # Don't let system headers trigger warnings + nw="$nw -Wsign-conversion" # Too many warnings for now + nw="$nw -Woverlength-strings" # Not a problem these days + nw="$nw -Wtraditional-conversion" # Too many warnings for now + nw="$nw -Wpadded" # Our structs are not padded + nw="$nw -Wredundant-decls" # We regularly (re)declare getenv etc. + nw="$nw -Wlogical-op" # any use of fwrite provokes this + nw="$nw -Wformat-nonliteral" # Emacs does this a lot + nw="$nw -Wvla" # warnings in gettext.h + nw="$nw -Wnested-externs" # use of XARGMATCH/verify_function__ + nw="$nw -Wswitch-enum" # Too many warnings for now + nw="$nw -Wswitch-default" # Too many warnings for now + nw="$nw -Wfloat-equal" # e.g., ftoastr.c + nw="$nw -Winline" # e.g., dispnew.c's inlining of row_equal_p + + # Emacs doesn't care about shadowing; see + # . + nw="$nw -Wshadow" + + # The following lines should be removable at some point. + nw="$nw -Wsuggest-attribute=const" + nw="$nw -Wsuggest-attribute=pure" + + gl_MANYWARN_ALL_GCC([ws]) + gl_MANYWARN_COMPLEMENT([ws], [$ws], [$nw]) + for w in $ws; do + gl_WARN_ADD([$w]) + done + gl_WARN_ADD([-Wno-missing-field-initializers]) # We need this one + gl_WARN_ADD([-Wno-sign-compare]) # Too many warnings for now + gl_WARN_ADD([-Wno-type-limits]) # Too many warnings for now + gl_WARN_ADD([-Wno-switch]) # Too many warnings for now + gl_WARN_ADD([-Wno-unused-parameter]) # Too many warnings for now + gl_WARN_ADD([-Wno-format-nonliteral]) + + # In spite of excluding -Wlogical-op above, it is enabled, as of + # gcc 4.5.0 20090517. + gl_WARN_ADD([-Wno-logical-op]) + + gl_WARN_ADD([-fdiagnostics-show-option]) + gl_WARN_ADD([-funit-at-a-time]) + + AC_SUBST([WARN_CFLAGS]) + + AC_DEFINE([lint], [1], [Define to 1 if the compiler is checking for lint.]) + AC_DEFINE([_FORTIFY_SOURCE], [2], + [enable compile-time and run-time bounds-checking, and some warnings]) + AC_DEFINE([GNULIB_PORTCHECK], [1], [enable some gnulib portability checks]) + + # We use a slightly smaller set of warning options for lib/. + # Remove the following and save the result in GNULIB_WARN_CFLAGS. + nw= + nw="$nw -Wunused-macros" + + gl_MANYWARN_COMPLEMENT([GNULIB_WARN_CFLAGS], [$WARN_CFLAGS], [$nw]) + AC_SUBST([GNULIB_WARN_CFLAGS]) +fi + #### Some other nice autoconf tests. @@ -1127,8 +1201,13 @@ AC_DEFUN([PKG_CHECK_MODULES], [ if $PKG_CONFIG --exists "$2" 2>&AS_MESSAGE_LOG_FD && $1_CFLAGS=`$PKG_CONFIG --cflags "$2" 2>&AS_MESSAGE_LOG_FD` && $1_LIBS=`$PKG_CONFIG --libs "$2" 2>&AS_MESSAGE_LOG_FD`; then - - $1_CFLAGS=`AS_ECHO(["$$1_CFLAGS"]) | sed -e 's,///*,/,g'` + edit_cflags=" + s,///*,/,g + s/^/ / + s/ -I/ $isystem/g + s/^ // + " + $1_CFLAGS=`AS_ECHO(["$$1_CFLAGS"]) | sed -e "$edit_cflags"` $1_LIBS=`AS_ECHO(["$$1_LIBS"]) | sed -e 's,///*,/,g'` AC_MSG_RESULT([yes CFLAGS='$$1_CFLAGS' LIBS='$$1_LIBS']) succeeded=yes @@ -1463,7 +1542,7 @@ AC_SUBST(LD_SWITCH_X_SITE_AUX) AC_SUBST(LD_SWITCH_X_SITE_AUX_RPATH) if test "${x_includes}" != NONE && test -n "${x_includes}"; then - C_SWITCH_X_SITE=-I`echo ${x_includes} | sed -e "s/:/ -I/g"` + C_SWITCH_X_SITE="$isystem"`echo ${x_includes} | sed -e "s/:/ $isystem/g"` fi if test x"${x_includes}" = x; then diff --git a/etc/NEWS b/etc/NEWS index ae6ba8d36b..dd302a052d 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -22,6 +22,13 @@ so we will look at it and add it to the manual. * Installation Changes in Emacs 24.2 + +** New configure option '--enable-gcc-warnings', intended for developers. +If building with GCC, this enables compile-time checks that warn about +possibly-questionable C code. On a recent GNU system there should be +no warnings; on older and on non-GNU systems the generated warnings +may or may not be useful. By default, these warnings are not generated. + * Startup Changes in Emacs 24.2 diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog index aad382de6d..86b92b5b84 100644 --- a/lib-src/ChangeLog +++ b/lib-src/ChangeLog @@ -1,3 +1,10 @@ +2012-04-09 Paul Eggert + + configure: new option --enable-gcc-warnings + * Makefile.in (C_WARNINGS_SWITCH): Remove. + (WARN_CFLAGS, WERROR_CFLAGS): New macros. + (BASE_CFLAGS): Use new macros rather than old. + 2012-04-07 Eli Zaretskii * makefile.w32-in (obj): Add xml.o. diff --git a/lib-src/Makefile.in b/lib-src/Makefile.in index cc1757e4e3..6732030a64 100644 --- a/lib-src/Makefile.in +++ b/lib-src/Makefile.in @@ -36,8 +36,9 @@ configuration=@configuration@ EXEEXT=@EXEEXT@ C_SWITCH_SYSTEM=@C_SWITCH_SYSTEM@ C_SWITCH_MACHINE=@C_SWITCH_MACHINE@ -C_WARNINGS_SWITCH = @C_WARNINGS_SWITCH@ PROFILING_CFLAGS = @PROFILING_CFLAGS@ +WARN_CFLAGS = @WARN_CFLAGS@ +WERROR_CFLAGS = @WERROR_CFLAGS@ # Program name transformation. TRANSFORM = @program_transform_name@ @@ -167,7 +168,8 @@ LIBS_SYSTEM = @LIBS_SYSTEM@ # Those files shared with other GNU utilities need HAVE_CONFIG_H # defined before they know they can take advantage of the information # in ../src/config.h. -BASE_CFLAGS = $(C_SWITCH_SYSTEM) $(C_SWITCH_MACHINE) ${C_WARNINGS_SWITCH} \ +BASE_CFLAGS = $(C_SWITCH_SYSTEM) $(C_SWITCH_MACHINE) \ + $(WARN_CFLAGS) $(WERROR_CFLAGS) \ -DHAVE_CONFIG_H -I. -I../src -I../lib \ -I${srcdir} -I${srcdir}/../src -I${srcdir}/../lib diff --git a/lib/Makefile.am b/lib/Makefile.am index 220ba713d4..716510aff9 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -4,6 +4,7 @@ MOSTLYCLEANDIRS = MOSTLYCLEANFILES = noinst_LIBRARIES = +AM_CFLAGS = $(GNULIB_WARN_CFLAGS) $(WERROR_CFLAGS) DEFAULT_INCLUDES = -I. -I../src -I$(top_srcdir)/src include gnulib.mk diff --git a/lwlib/ChangeLog b/lwlib/ChangeLog index a4bb243f35..f4800bc4bb 100644 --- a/lwlib/ChangeLog +++ b/lwlib/ChangeLog @@ -1,3 +1,10 @@ +2012-04-09 Paul Eggert + + configure: new option --enable-gcc-warnings + * Makefile.in (C_WARNINGS_SWITCH): Remove. + (WARN_CFLAGS, WERROR_CFLAGS): New macros. + (ALL_CFLAGS): Use new macros rather than old. + 2011-10-13 Dmitry Antipov * lwlib-Xaw.c (openFont, xaw_destroy_instance): Replace free with diff --git a/lwlib/Makefile.in b/lwlib/Makefile.in index db108862d7..76507ac4b2 100644 --- a/lwlib/Makefile.in +++ b/lwlib/Makefile.in @@ -29,8 +29,9 @@ C_SWITCH_X_SITE=@C_SWITCH_X_SITE@ C_SWITCH_X_SYSTEM=@C_SWITCH_X_SYSTEM@ C_SWITCH_SYSTEM=@C_SWITCH_SYSTEM@ C_SWITCH_MACHINE=@C_SWITCH_MACHINE@ -C_WARNINGS_SWITCH = @C_WARNINGS_SWITCH@ PROFILING_CFLAGS = @PROFILING_CFLAGS@ +WARN_CFLAGS = `echo @WARN_CFLAGS@ | sed 's/ -Wwrite-strings//'` +WERROR_CFLAGS = @WERROR_CFLAGS@ CC=@CC@ CFLAGS=@CFLAGS@ @@ -54,7 +55,8 @@ OBJS = lwlib.o $(TOOLKIT_OBJS) lwlib-utils.o ## There are no generated lwlib files, hence no need for -I. ALL_CFLAGS= $(C_SWITCH_SYSTEM) $(C_SWITCH_X_SITE) \ $(C_SWITCH_X_SYSTEM) $(C_SWITCH_MACHINE) \ - $(C_WARNINGS_SWITCH) $(PROFILING_CFLAGS) $(CFLAGS) \ + $(WARN_CFLAGS) $(WERROR_CFLAGS) \ + $(PROFILING_CFLAGS) $(CFLAGS) \ -DHAVE_CONFIG_H -Demacs -I../src \ -I$(srcdir) -I$(srcdir)/../src -I../lib -I$(srcdir)/../lib diff --git a/m4/manywarnings.m4 b/m4/manywarnings.m4 new file mode 100644 index 0000000000..fd0e3722d3 --- /dev/null +++ b/m4/manywarnings.m4 @@ -0,0 +1,184 @@ +# manywarnings.m4 serial 3 +dnl Copyright (C) 2008-2012 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_MANYWARN_COMPLEMENT(OUTVAR, LISTVAR, REMOVEVAR) +# -------------------------------------------------- +# Copy LISTVAR to OUTVAR except for the entries in REMOVEVAR. +# Elements separated by whitespace. In set logic terms, the function +# does OUTVAR = LISTVAR \ REMOVEVAR. +AC_DEFUN([gl_MANYWARN_COMPLEMENT], +[ + gl_warn_set= + set x $2; shift + for gl_warn_item + do + case " $3 " in + *" $gl_warn_item "*) + ;; + *) + gl_warn_set="$gl_warn_set $gl_warn_item" + ;; + esac + done + $1=$gl_warn_set +]) + +# gl_MANYWARN_ALL_GCC(VARIABLE) +# ----------------------------- +# Add all documented GCC warning parameters to variable VARIABLE. +# Note that you need to test them using gl_WARN_ADD if you want to +# make sure your gcc understands it. +AC_DEFUN([gl_MANYWARN_ALL_GCC], +[ + dnl First, check if -Wno-missing-field-initializers is needed. + dnl -Wmissing-field-initializers is implied by -W, but that issues + dnl warnings with GCC version before 4.7, for the common idiom + dnl of initializing types on the stack to zero, using { 0, } + AC_REQUIRE([AC_PROG_CC]) + if test -n "$GCC"; then + + dnl First, check -W -Werror -Wno-missing-field-initializers is supported + dnl with the current $CC $CFLAGS $CPPFLAGS. + AC_MSG_CHECKING([whether -Wno-missing-field-initializers is supported]) + AC_CACHE_VAL([gl_cv_cc_nomfi_supported], [ + gl_save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -W -Werror -Wno-missing-field-initializers" + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[]], [[]])], + [gl_cv_cc_nomfi_supported=yes], + [gl_cv_cc_nomfi_supported=no]) + CFLAGS="$gl_save_CFLAGS"]) + AC_MSG_RESULT([$gl_cv_cc_nomfi_supported]) + + if test "$gl_cv_cc_nomfi_supported" = yes; then + dnl Now check whether -Wno-missing-field-initializers is needed + dnl for the { 0, } construct. + AC_MSG_CHECKING([whether -Wno-missing-field-initializers is needed]) + AC_CACHE_VAL([gl_cv_cc_nomfi_needed], [ + gl_save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -W -Werror" + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[void f (void) + { + typedef struct { int a; int b; } s_t; + s_t s1 = { 0, }; + } + ]], + [[]])], + [gl_cv_cc_nomfi_needed=no], + [gl_cv_cc_nomfi_needed=yes]) + CFLAGS="$gl_save_CFLAGS" + ]) + AC_MSG_RESULT([$gl_cv_cc_nomfi_needed]) + fi + fi + + gl_manywarn_set= + for gl_manywarn_item in \ + -Wall \ + -W \ + -Wformat-y2k \ + -Wformat-nonliteral \ + -Wformat-security \ + -Winit-self \ + -Wmissing-include-dirs \ + -Wswitch-default \ + -Wswitch-enum \ + -Wunused \ + -Wunknown-pragmas \ + -Wstrict-aliasing \ + -Wstrict-overflow \ + -Wsystem-headers \ + -Wfloat-equal \ + -Wtraditional \ + -Wtraditional-conversion \ + -Wdeclaration-after-statement \ + -Wundef \ + -Wshadow \ + -Wunsafe-loop-optimizations \ + -Wpointer-arith \ + -Wbad-function-cast \ + -Wc++-compat \ + -Wcast-qual \ + -Wcast-align \ + -Wwrite-strings \ + -Wconversion \ + -Wsign-conversion \ + -Wlogical-op \ + -Waggregate-return \ + -Wstrict-prototypes \ + -Wold-style-definition \ + -Wmissing-prototypes \ + -Wmissing-declarations \ + -Wmissing-noreturn \ + -Wmissing-format-attribute \ + -Wpacked \ + -Wpadded \ + -Wredundant-decls \ + -Wnested-externs \ + -Wunreachable-code \ + -Winline \ + -Winvalid-pch \ + -Wlong-long \ + -Wvla \ + -Wvolatile-register-var \ + -Wdisabled-optimization \ + -Wstack-protector \ + -Woverlength-strings \ + -Wbuiltin-macro-redefined \ + -Wmudflap \ + -Wpacked-bitfield-compat \ + -Wsync-nand \ + ; do + gl_manywarn_set="$gl_manywarn_set $gl_manywarn_item" + done + # The following are not documented in the manual but are included in + # output from gcc --help=warnings. + for gl_manywarn_item in \ + -Wattributes \ + -Wcoverage-mismatch \ + -Wmultichar \ + -Wunused-macros \ + ; do + gl_manywarn_set="$gl_manywarn_set $gl_manywarn_item" + done + # More warnings from gcc 4.6.2 --help=warnings. + for gl_manywarn_item in \ + -Wabi \ + -Wcpp \ + -Wdeprecated \ + -Wdeprecated-declarations \ + -Wdiv-by-zero \ + -Wdouble-promotion \ + -Wendif-labels \ + -Wextra \ + -Wformat-contains-nul \ + -Wformat-extra-args \ + -Wformat-zero-length \ + -Wformat=2 \ + -Wmultichar \ + -Wnormalized=nfc \ + -Woverflow \ + -Wpointer-to-int-cast \ + -Wpragmas \ + -Wsuggest-attribute=const \ + -Wsuggest-attribute=noreturn \ + -Wsuggest-attribute=pure \ + -Wtrampolines \ + ; do + gl_manywarn_set="$gl_manywarn_set $gl_manywarn_item" + done + + # Disable the missing-field-initializers warning if needed + if test "$gl_cv_cc_nomfi_needed" = yes; then + gl_manywarn_set="$gl_manywarn_set -Wno-missing-field-initializers" + fi + + $1=$gl_manywarn_set +]) diff --git a/m4/warnings.m4 b/m4/warnings.m4 new file mode 100644 index 0000000000..c14c4801e7 --- /dev/null +++ b/m4/warnings.m4 @@ -0,0 +1,42 @@ +# warnings.m4 serial 6 +dnl Copyright (C) 2008-2012 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_WARN_ADD(PARAMETER, [VARIABLE = WARN_CFLAGS]) +# ------------------------------------------------ +# Adds parameter to WARN_CFLAGS if the compiler supports it. For example, +# gl_WARN_ADD([-Wparentheses]). +# +# If VARIABLE is a variable name, AC_SUBST it. +AC_DEFUN([gl_WARN_ADD], +dnl FIXME: gl_Warn must be used unquoted until we can assume +dnl autoconf 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 +AC_CACHE_CHECK([whether _AC_LANG compiler handles $1], m4_defn([gl_Warn]), [ + gl_save_compiler_FLAGS="$gl_Flags" + gl_Flags="$gl_Flags $1" + AC_COMPILE_IFELSE([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], + [gl_AS_VAR_APPEND(m4_if([$2], [], [[WARN_CFLAGS]], [[$2]]), [" $1"])]) +AS_VAR_POPDEF([gl_Flags])dnl +AS_VAR_POPDEF([gl_Warn])dnl +m4_ifval([$2], [AS_LITERAL_IF([$2], [AC_SUBST([$2])], [])])dnl +]) diff --git a/oldXMenu/ChangeLog b/oldXMenu/ChangeLog index 1d3091c6bb..f5d65b4967 100644 --- a/oldXMenu/ChangeLog +++ b/oldXMenu/ChangeLog @@ -1,3 +1,10 @@ +2012-04-09 Paul Eggert + + configure: new option --enable-gcc-warnings + * Makefile.in (C_WARNINGS_SWITCH): Remove. + (WARN_CFLAGS, WERROR_CFLAGS): New macros. + (ALL_CFLAGS): Use new macros rather than old. + 2011-04-16 Paul Eggert Static checks with GCC 4.6.0 and non-default toolkits. diff --git a/oldXMenu/Makefile.in b/oldXMenu/Makefile.in index 94c49fb996..e7bc402cb0 100644 --- a/oldXMenu/Makefile.in +++ b/oldXMenu/Makefile.in @@ -48,8 +48,9 @@ C_SWITCH_X_SITE=@C_SWITCH_X_SITE@ C_SWITCH_X_SYSTEM=@C_SWITCH_X_SYSTEM@ C_SWITCH_SYSTEM=@C_SWITCH_SYSTEM@ C_SWITCH_MACHINE=@C_SWITCH_MACHINE@ -C_WARNINGS_SWITCH = @C_WARNINGS_SWITCH@ PROFILING_CFLAGS = @PROFILING_CFLAGS@ +WARN_CFLAGS = @WARN_CFLAGS@ +WERROR_CFLAGS = @WERROR_CFLAGS@ EXTRA=insque.o CC=@CC@ @@ -89,7 +90,7 @@ all:: libXMenu11.a ALL_CFLAGS=$(C_SWITCH_SYSTEM) $(C_SWITCH_MACHINE) \ $(C_SWITCH_X_SITE) $(C_SWITCH_X_SYSTEM) \ - ${C_WARNINGS_SWITCH} ${PROFILING_CFLAGS} \ + $(WARN_CFLAGS) $(WERROR_CFLAGS) ${C_WARNINGS_SWITCH} ${PROFILING_CFLAGS} \ $(CPPFLAGS) $(CFLAGS) -DEMACS_BITMAP_FILES \ -I../src -I${srcdir} -I${srcdir}/../src diff --git a/src/ChangeLog b/src/ChangeLog index dbff8e3549..df3336b52e 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,16 @@ +2012-04-09 Paul Eggert + + configure: new option --enable-gcc-warnings + * Makefile.in (C_WARNINGS_SWITCH): Remove. + (WARN_CFLAGS, WERROR_CFLAGS): New macros. + (ALL_CFLAGS): Use new macros rather than old. + * process.c: Ignore -Wstrict-overflow to work around GCC bug 52904. + * regex.c: Ignore -Wstrict-overflow. If !emacs, also ignore + -Wunused-but-set-variable, -Wunused-function, -Wunused-macros, + -Wunused-result, -Wunused-variable. This should go away once + the Emacs and Gnulib regex code is merged. + (xmalloc, xrealloc): Now static. + 2012-04-09 Paul Eggert composite.c: use 'double' consistently diff --git a/src/Makefile.in b/src/Makefile.in index 8c3704f830..19f586396c 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -68,7 +68,8 @@ OTHER_FILES = @OTHER_FILES@ PROFILING_CFLAGS = @PROFILING_CFLAGS@ ## Flags to pass to the compiler to enable build warnings -C_WARNINGS_SWITCH = @C_WARNINGS_SWITCH@ +WARN_CFLAGS = @WARN_CFLAGS@ +WERROR_CFLAGS = @WERROR_CFLAGS@ ## Machine-specific CFLAGS. C_SWITCH_MACHINE=@C_SWITCH_MACHINE@ @@ -314,7 +315,7 @@ ALL_CFLAGS=-Demacs -DHAVE_CONFIG_H $(MYCPPFLAGS) -I. -I$(srcdir) \ $(SETTINGS_CFLAGS) $(FREETYPE_CFLAGS) $(FONTCONFIG_CFLAGS) \ $(LIBOTF_CFLAGS) $(M17N_FLT_CFLAGS) $(DEPFLAGS) $(PROFILING_CFLAGS) \ $(LIBGNUTLS_CFLAGS) \ - $(C_WARNINGS_SWITCH) $(CFLAGS) + $(WARN_CFLAGS) $(WERROR_CFLAGS) $(CFLAGS) ALL_OBJC_CFLAGS=$(ALL_CFLAGS) $(GNU_OBJC_CFLAGS) .SUFFIXES: .m diff --git a/src/process.c b/src/process.c index f2f33a9eaf..f14de474ee 100644 --- a/src/process.c +++ b/src/process.c @@ -120,6 +120,13 @@ along with GNU Emacs. If not, see . */ #include "nsterm.h" #endif +/* Work around GCC 4.7.0 bug with strict overflow checking; see + . + These lines can be removed once the GCC bug is fixed. */ +#if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < __GNUC__ +# pragma GCC diagnostic ignored "-Wstrict-overflow" +#endif + Lisp_Object Qeuid, Qegid, Qcomm, Qstate, Qppid, Qpgrp, Qsess, Qttname, Qtpgid; Lisp_Object Qminflt, Qmajflt, Qcminflt, Qcmajflt, Qutime, Qstime, Qcstime; Lisp_Object Qcutime, Qpri, Qnice, Qthcount, Qstart, Qvsize, Qrss, Qargs; diff --git a/src/regex.c b/src/regex.c index 0f9150193e..d16a514805 100644 --- a/src/regex.c +++ b/src/regex.c @@ -33,6 +33,19 @@ #pragma alloca #endif +/* Ignore some GCC warnings for now. This section should go away + once the Emacs and Gnulib regex code is merged. */ +#if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < __GNUC__ +# pragma GCC diagnostic ignored "-Wstrict-overflow" +# ifndef emacs +# pragma GCC diagnostic ignored "-Wunused-but-set-variable" +# pragma GCC diagnostic ignored "-Wunused-function" +# pragma GCC diagnostic ignored "-Wunused-macros" +# pragma GCC diagnostic ignored "-Wunused-result" +# pragma GCC diagnostic ignored "-Wunused-variable" +# endif +#endif + #ifdef HAVE_CONFIG_H # include #endif @@ -198,7 +211,7 @@ /* When used in Emacs's lib-src, we need xmalloc and xrealloc. */ -void * +static void * xmalloc (size_t size) { register void *val; @@ -211,7 +224,7 @@ xmalloc (size_t size) return val; } -void * +static void * xrealloc (void *block, size_t size) { register void *val; -- 2.20.1