diff options
author | Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com> | 2021-07-12 11:48:32 +0200 |
---|---|---|
committer | Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com> | 2021-07-19 12:53:25 +0200 |
commit | 3c15340c861c4011e225c0da9ad781fc7a9fd79d (patch) | |
tree | e583a48f927f57c8716e3a4dd7375fc0af27942e | |
parent | 4119c7d86af972f51d7e1b9adfecdc8f03bf7a92 (diff) | |
download | neard-3c15340c861c4011e225c0da9ad781fc7a9fd79d.tar.gz |
build: enable -Wunsafe-loop-optimizations and -Wstrict-overflow=2 warnings
Enable basic overflow in optimization checks (portability related) and
missed loop optimizations. The latter (-Wunsafe-loop-optimizations)
does not work well with GCC v7.5 so simply skip it there.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
-rw-r--r-- | accflags.m4 | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/accflags.m4 b/accflags.m4 index 57cc48b..0030ac3 100644 --- a/accflags.m4 +++ b/accflags.m4 @@ -24,6 +24,7 @@ AC_DEFUN([NEARD_COMPILER_FLAGS], [ AX_CHECK_COMPILE_FLAG([-Wjump-misses-init], [CFLAGS="$CFLAGS -Wjump-misses-init"]) AX_CHECK_COMPILE_FLAG([-Wpointer-arith], [CFLAGS="$CFLAGS -Wpointer-arith"]) AX_CHECK_COMPILE_FLAG([-Wshadow], [CFLAGS="$CFLAGS -Wshadow"]) + AX_CHECK_COMPILE_FLAG([-Wstrict-overflow=2], [CFLAGS="$CFLAGS -Wstrict-overflow=2"]) # GCC v5.0 AX_CHECK_COMPILE_FLAG([-Wformat-signedness], [CFLAGS="$CFLAGS -Wformat-signedness"]) @@ -36,10 +37,16 @@ AC_DEFUN([NEARD_COMPILER_FLAGS], [ AX_CHECK_COMPILE_FLAG([-Walloc-zero], [CFLAGS="$CFLAGS -Walloc-zero"]) # GCC v8.0 AX_CHECK_COMPILE_FLAG([-Wstringop-truncation], [CFLAGS="$CFLAGS -Wstringop-truncation"]) + + # GCC v7.5 from Ubuntu Bionic incorrectly assumes several loops can overflow, so enable + # -Wunsafe-loop-optimizations only on newer GCC. + CC_VERSION=`$CC --version | head -n 1 | sed -e 's/.*\ \(@<:@0-9@:>@\+\.@<:@0-9@:>@\+\.@<:@0-9@:>@\+\)\(-@<:@0-9@:>@\+\)\?$/\1/'` + AX_COMPARE_VERSION([$CC_VERSION],[ge],[8.0.0], + [AX_CHECK_COMPILE_FLAG([-Wunsafe-loop-optimizations], [CFLAGS="$CFLAGS -Wunsafe-loop-optimizations"])], []) fi if (test "$USE_MAINTAINER_MODE" = "pedantic"); then - AX_CHECK_COMPILE_FLAG([-Wstrict-overflow=3], [CFLAGS="$CFLAGS -Wstrict-overflow=3"]) AX_CHECK_COMPILE_FLAG([-Wcast-qual], [CFLAGS="$CFLAGS -Wcast-qual"]) - AX_CHECK_COMPILE_FLAG([-Wunsafe-loop-optimizations], [CFLAGS="$CFLAGS -Wunsafe-loop-optimizations"]) + # Instead of -Wstrict-overflow=2 + AX_CHECK_COMPILE_FLAG([-Wstrict-overflow=3], [CFLAGS="$CFLAGS -Wstrict-overflow=3"]) fi ]) |