Skip to content

Commit

Permalink
BUILD: Make use of GNULIB's compiler warning code
Browse files Browse the repository at this point in the history
As GNULIB has the 'manywarnings' module, which basically turns on every
GCC warning, let's make use of it. We can easily blacklist the warnings
we cannot cope with, but the main goal should be to have enabled every
possible GCC warning.

When new GCC warnings are created the 'manywarnings' file can be
refreshed from upstream GNULIB.

Compilation with -Werror is explicitly disabled for RHEL6 in our CI, as
a lot of warnings show up there due to old dependencies or even as
false-positives.

Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
  • Loading branch information
fidencio committed Nov 10, 2016
1 parent dc7c6e7 commit e2a7403
Show file tree
Hide file tree
Showing 6 changed files with 459 additions and 6 deletions.
7 changes: 1 addition & 6 deletions Makefile.am
Expand Up @@ -103,12 +103,7 @@ if WANT_AUX_INFO
AM_CFLAGS += -aux-info $@.X
endif
if HAVE_GCC
AM_CFLAGS += -Wall -Wshadow -Wstrict-prototypes -Wpointer-arith \
-Wcast-qual -Wcast-align -Wwrite-strings -Wundef \
-Werror-implicit-function-declaration -Winit-self \
-Wmissing-include-dirs \
-fno-strict-aliasing \
-std=gnu99
AM_CFLAGS += $(WARN_CFLAGS)
endif

pkgconfig_DATA =
Expand Down
5 changes: 5 additions & 0 deletions configure.ac
Expand Up @@ -11,6 +11,11 @@ m4_ifdef([AC_USE_SYSTEM_EXTENSIONS],
[AC_USE_SYSTEM_EXTENSIONS],
[AC_GNU_SOURCE])

m4_include([src/warnings.m4])
m4_include([src/manywarnings.m4])
m4_include([src/sssd-compile-warnings.m4])
SSSD_COMPILE_WARNINGS

CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE"


Expand Down
1 change: 1 addition & 0 deletions contrib/ci/configure.sh
Expand Up @@ -38,6 +38,7 @@ if [[ "$DISTRO_BRANCH" == -redhat-redhatenterprise*-6.*- ||
"--disable-cifs-idmap-plugin"
"--with-syslog=syslog"
"--without-python3-bindings"
"--enable-werror=no"
)
fi

Expand Down
274 changes: 274 additions & 0 deletions src/manywarnings.m4
@@ -0,0 +1,274 @@
# manywarnings.m4 serial 8
dnl Copyright (C) 2008-2016 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 for some issues that only occur when combining multiple
dnl gcc warning categories.
AC_REQUIRE([AC_PROG_CC])
if test -n "$GCC"; then
dnl Check if -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
dnl Next, check if -Werror -Wuninitialized is useful with the
dnl user's choice of $CFLAGS; some versions of gcc warn that it
dnl has no effect if -O is not also used
AC_MSG_CHECKING([whether -Wuninitialized is supported])
AC_CACHE_VAL([gl_cv_cc_uninitialized_supported], [
gl_save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -Werror -Wuninitialized"
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[]], [[]])],
[gl_cv_cc_uninitialized_supported=yes],
[gl_cv_cc_uninitialized_supported=no])
CFLAGS="$gl_save_CFLAGS"])
AC_MSG_RESULT([$gl_cv_cc_uninitialized_supported])
fi
# List all gcc warning categories.
# To compare this list to your installed GCC's, run this Bash command:
#
# comm -3 \
# <(sed -n 's/^ *\(-[^ ]*\) .*/\1/p' manywarnings.m4 | sort) \
# <(gcc --help=warnings | sed -n 's/^ \(-[^ ]*\) .*/\1/p' | sort |
# grep -v -x -f <(
# awk '/^[^#]/ {print $1}' ../build-aux/gcc-warning.spec))
gl_manywarn_set=
for gl_manywarn_item in \
-W \
-Wabi \
-Waddress \
-Waggressive-loop-optimizations \
-Wall \
-Wattributes \
-Wbad-function-cast \
-Wbool-compare \
-Wbuiltin-macro-redefined \
-Wcast-align \
-Wchar-subscripts \
-Wchkp \
-Wclobbered \
-Wcomment \
-Wcomments \
-Wcoverage-mismatch \
-Wcpp \
-Wdate-time \
-Wdeprecated \
-Wdeprecated-declarations \
-Wdesignated-init \
-Wdisabled-optimization \
-Wdiscarded-array-qualifiers \
-Wdiscarded-qualifiers \
-Wdiv-by-zero \
-Wdouble-promotion \
-Wduplicated-cond \
-Wempty-body \
-Wendif-labels \
-Wenum-compare \
-Wextra \
-Wformat-contains-nul \
-Wformat-extra-args \
-Wformat-nonliteral \
-Wformat-security \
-Wformat-signedness \
-Wformat-y2k \
-Wformat-zero-length \
-Wframe-address \
-Wfree-nonheap-object \
-Whsa \
-Wignored-attributes \
-Wignored-qualifiers \
-Wimplicit \
-Wimplicit-function-declaration \
-Wimplicit-int \
-Wincompatible-pointer-types \
-Winit-self \
-Winline \
-Wint-conversion \
-Wint-to-pointer-cast \
-Winvalid-memory-model \
-Winvalid-pch \
-Wjump-misses-init \
-Wlogical-not-parentheses \
-Wlogical-op \
-Wmain \
-Wmaybe-uninitialized \
-Wmemset-transposed-args \
-Wmisleading-indentation \
-Wmissing-braces \
-Wmissing-declarations \
-Wmissing-field-initializers \
-Wmissing-include-dirs \
-Wmissing-parameter-type \
-Wmissing-prototypes \
-Wmultichar \
-Wnarrowing \
-Wnested-externs \
-Wnonnull \
-Wnonnull-compare \
-Wnull-dereference \
-Wodr \
-Wold-style-declaration \
-Wold-style-definition \
-Wopenmp-simd \
-Woverflow \
-Woverlength-strings \
-Woverride-init \
-Wpacked \
-Wpacked-bitfield-compat \
-Wparentheses \
-Wpointer-arith \
-Wpointer-sign \
-Wpointer-to-int-cast \
-Wpragmas \
-Wreturn-local-addr \
-Wreturn-type \
-Wscalar-storage-order \
-Wsequence-point \
-Wshadow \
-Wshift-count-negative \
-Wshift-count-overflow \
-Wshift-negative-value \
-Wsizeof-array-argument \
-Wsizeof-pointer-memaccess \
-Wstack-protector \
-Wstrict-aliasing \
-Wstrict-overflow \
-Wstrict-prototypes \
-Wsuggest-attribute=const \
-Wsuggest-attribute=format \
-Wsuggest-attribute=noreturn \
-Wsuggest-attribute=pure \
-Wsuggest-final-methods \
-Wsuggest-final-types \
-Wswitch \
-Wswitch-bool \
-Wswitch-default \
-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 \
-Wunused-variable \
-Wvarargs \
-Wvariadic-macros \
-Wvector-operation-performance \
-Wvla \
-Wvolatile-register-var \
-Wwrite-strings \
\
; do
gl_manywarn_set="$gl_manywarn_set $gl_manywarn_item"
done
# gcc --help=warnings outputs an unusual form for these options; list
# them here so that the above 'comm' command doesn't report a false match.
gl_manywarn_set="$gl_manywarn_set -Warray-bounds=2"
gl_manywarn_set="$gl_manywarn_set -Wnormalized=nfc"
gl_manywarn_set="$gl_manywarn_set -Wshift-overflow=2"
gl_manywarn_set="$gl_manywarn_set -Wunused-const-variable=2"
# These are needed for older GCC versions.
if test -n "$GCC"; then
case `($CC --version) 2>/dev/null` in
'gcc (GCC) '[[0-3]].* | \
'gcc (GCC) '4.[[0-7]].*)
gl_manywarn_set="$gl_manywarn_set -fdiagnostics-show-option"
gl_manywarn_set="$gl_manywarn_set -funit-at-a-time"
;;
esac
fi
# Disable specific options as needed.
if test "$gl_cv_cc_nomfi_needed" = yes; then
gl_manywarn_set="$gl_manywarn_set -Wno-missing-field-initializers"
fi
if test "$gl_cv_cc_uninitialized_supported" = no; then
gl_manywarn_set="$gl_manywarn_set -Wno-uninitialized"
fi
$1=$gl_manywarn_set
])

0 comments on commit e2a7403

Please sign in to comment.