build: disable warnings that trigger known clang problems

Fixes build with clang 3.5 on Fedora 21.
This commit is contained in:
Lubomir Rintel
2015-03-18 19:02:29 +01:00
parent 3ccc6f290d
commit f0740aff88

View File

@@ -1,3 +1,24 @@
dnl Check whether a particular compiler flag works with code provided,
dnl disable it in CFLAGS if the check fails.
AC_DEFUN([NM_COMPILER_WARNING], [
CFLAGS_SAVED="$CFLAGS"
CFLAGS="$CFLAGS -Werror -W$1"
AC_MSG_CHECKING(whether -W$1 works)
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[]])], [
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[$2]])], [
AC_MSG_RESULT(yes)
CFLAGS="$CFLAGS_SAVED -W$1"
],[
AC_MSG_RESULT(no)
CFLAGS="$CFLAGS_SAVED -Wno-$1"
])
],[
AC_MSG_RESULT(not supported)
CFLAGS="$CFLAGS_SAVED"
])
])
AC_DEFUN([NM_COMPILER_WARNINGS], AC_DEFUN([NM_COMPILER_WARNINGS],
[AC_ARG_ENABLE(more-warnings, [AC_ARG_ENABLE(more-warnings,
AS_HELP_STRING([--enable-more-warnings], [Possible values: no/yes/error]), AS_HELP_STRING([--enable-more-warnings], [Possible values: no/yes/error]),
@@ -5,22 +26,26 @@ AC_DEFUN([NM_COMPILER_WARNINGS],
AC_MSG_CHECKING(for more warnings) AC_MSG_CHECKING(for more warnings)
if test "$GCC" = "yes" -a "$set_more_warnings" != "no"; then if test "$GCC" = "yes" -a "$set_more_warnings" != "no"; then
AC_MSG_RESULT(yes) AC_MSG_RESULT(yes)
dnl This is enabled in clang by default, makes little sense,
dnl and causes the build to abort with -Werror.
CFLAGS_SAVED="$CFLAGS" CFLAGS_SAVED="$CFLAGS"
CFLAGS_MORE_WARNINGS="-Wall -std=gnu89" CFLAGS="$CFLAGS -Qunused-arguments"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([])], [], CFLAGS="$CFLAGS_SAVED")
unset CFLAGS_SAVED
dnl clang only warns about unknown warnings, unless dnl clang only warns about unknown warnings, unless
dnl called with "-Werror=unknown-warning-option" dnl called with "-Werror=unknown-warning-option"
dnl Test if the compiler supports that, and if it does dnl Test if the compiler supports that, and if it does
dnl attach it to the CFLAGS. dnl attach it to the CFLAGS.
CFLAGS_EXTRA="-Werror=unknown-warning-option" NM_COMPILER_WARNING([unknown-warning-option], [])
CFLAGS="$CFLAGS_MORE_WARNINGS $CFLAGS_EXTRA $CFLAGS_SAVED"
AC_TRY_COMPILE([], [], CFLAGS_SAVED="$CFLAGS"
has_option=yes, CFLAGS_MORE_WARNINGS="-Wall -std=gnu89"
has_option=no,)
if test $has_option = no; then if test "x$set_more_warnings" = xerror; then
CFLAGS_EXTRA= CFLAGS_MORE_WARNINGS="$CFLAGS_MORE_WARNINGS -Werror"
fi fi
unset has_option
for option in -Wshadow -Wmissing-declarations -Wmissing-prototypes \ for option in -Wshadow -Wmissing-declarations -Wmissing-prototypes \
-Wdeclaration-after-statement -Wformat-security \ -Wdeclaration-after-statement -Wformat-security \
@@ -31,8 +56,8 @@ if test "$GCC" = "yes" -a "$set_more_warnings" != "no"; then
-Wpointer-arith -Winit-self \ -Wpointer-arith -Winit-self \
-Wmissing-include-dirs -Wno-pragmas; do -Wmissing-include-dirs -Wno-pragmas; do
dnl GCC 4.4 does not warn when checking for -Wno-* flags (https://gcc.gnu.org/wiki/FAQ#wnowarning) dnl GCC 4.4 does not warn when checking for -Wno-* flags (https://gcc.gnu.org/wiki/FAQ#wnowarning)
CFLAGS="$CFLAGS_MORE_WARNINGS $CFLAGS_EXTRA $(printf '%s' "$option" | sed 's/^-Wno-/-W/') $CFLAGS_SAVED" CFLAGS="$CFLAGS_MORE_WARNINGS $(printf '%s' "$option" | sed 's/^-Wno-/-W/') $CFLAGS_SAVED"
AC_MSG_CHECKING([whether gcc understands $option]) AC_MSG_CHECKING([whether compiler understands $option])
AC_TRY_COMPILE([], [], AC_TRY_COMPILE([], [],
has_option=yes, has_option=yes,
has_option=no,) has_option=no,)
@@ -43,12 +68,35 @@ if test "$GCC" = "yes" -a "$set_more_warnings" != "no"; then
unset has_option unset has_option
done done
unset option unset option
unset CFLAGS_EXTRA
if test "x$set_more_warnings" = xerror; then CFLAGS="$CFLAGS_SAVED"
CFLAGS_MORE_WARNINGS="$CFLAGS_MORE_WARNINGS -Werror"
fi
CFLAGS="$CFLAGS_MORE_WARNINGS $CFLAGS_SAVED"
unset CFLAGS_SAVED unset CFLAGS_SAVED
dnl Disable warnings triggered by known compiler problems
dnl https://bugzilla.gnome.org/show_bug.cgi?id=745821
NM_COMPILER_WARNING([unknown-attributes], [#include <glib.h>])
dnl https://llvm.org/bugs/show_bug.cgi?id=21614
NM_COMPILER_WARNING([array-bounds],
[#include <string.h>]
[void f () { strcmp ("something", "0"); }]
)
dnl https://llvm.org/bugs/show_bug.cgi?id=22949
NM_COMPILER_WARNING([parentheses-equality],
[#include <sys/wait.h>]
[void f () { if (WIFCONTINUED(0)) return; }]
)
dnl systemd-dhcp's log_internal macro and our handle_warn are sometimes
dnl used in void context,u sometimes in int. Makes clang unhappy.
NM_COMPILER_WARNING([unused-value],
[#define yolo ({ (666 + 666); })]
[int f () { int i = yolo; yolo; return i; }]
)
CFLAGS="$CFLAGS_MORE_WARNINGS $CFLAGS"
else else
AC_MSG_RESULT(no) AC_MSG_RESULT(no)
fi fi