Skip to content

Commit

Permalink
build: disable some gcc compier warnings
Browse files Browse the repository at this point in the history
Add --enable-extra-warning option to the configure script. By default,
it is disabled to suppress some gcc warnings:

* -Wno-misleading-indentation. This is because, for the short term, it
  seems unfeasible to clearly rewrite FORM source code (by hand) unless
  we introduce some automatization with formatters, linters or static
  analyzers.

* -Wno-stringop-overflow. It seems to give many false positives (though
  there may be some true positives).

Stop using obsolete macros when autoconf>=2.70 is used.

Improve the handling of i486 (Pentium) processors on old 32-bit systems
(-march=i486).

ax_check_compile_flag.m4 (GPL-3.0-or-later) is taken from:
  autoconf-archive/autoconf-archive@7f56aaa (v2014.10.15)

Resolve vermaseren#416
  • Loading branch information
tueda committed Nov 12, 2022
1 parent 9a149d4 commit d5f9d33
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 56 deletions.
118 changes: 62 additions & 56 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ m4_define([serial_tests], [m4_esyscmd_s([
awk '{split ($NF,a,"."); if (a[1] >= 2 || (a[1] == 1 && a[2] >= 13)) { print "serial-tests" }}'
])])

AC_PREREQ(2.59)
AC_INIT([FORM], FORM_VERSION, [https://github.com/vermaseren/form/issues])
AC_PREREQ([2.59])
AC_INIT([FORM], [FORM_VERSION], [https://github.com/vermaseren/form/issues])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SRCDIR([sources/form3.h])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_AUX_DIR([build-aux])
Expand Down Expand Up @@ -96,8 +97,18 @@ AC_PROG_CXX([g++ c++ icpc])
AC_PROG_LN_S

# Checks for header files
AC_HEADER_STDC
AC_HEADER_TIME
# NOTE: autoconf>=2.70 has started to warn obsolete macros.
# We check if AC_CHECK_INCLUDES_DEFAULT (introduced in 2.70) is available
# and switch to the new code if possible.
m4_ifdef([AC_CHECK_INCLUDES_DEFAULT],
[AC_CHECK_INCLUDES_DEFAULT
AC_PROG_EGREP
AC_CHECK_HEADERS_ONCE([sys/time.h])
AC_DEFINE([TIME_WITH_SYS_TIME],
[1],
[Define to 1 if you can safely include both <sys/time.h> and <time.h>. This macro is obsolete.])],
[AC_HEADER_STDC
AC_HEADER_TIME])
AC_CHECK_HEADERS([fcntl.h limits.h sys/file.h])

AC_LANG_PUSH([C++])
Expand Down Expand Up @@ -160,17 +171,20 @@ case $host_os in
;;
esac
case $host_cpu in
i?86 )
i586 )
print_cpu="Pentium"
;;
i686 )
print_cpu="Pentium Pro"
;;
x86_64 )
print_cpu="Opteron"
;;
alpha* )
print_cpu="Alpha"
;;
* )
print_cpu="UNKNOWN CPU"
print_cpu="UNKNOWN CPU ($host_cpu)"
;;
esac

Expand Down Expand Up @@ -730,6 +744,13 @@ AC_ARG_ENABLE([sanitize],
[enable_sanitize=no])],
[enable_sanitize=no])

# Check for extra compiler warnings
AC_ARG_ENABLE([extra-warning],
[AS_HELP_STRING([--enable-extra-warning],
[enable extra compiler warnings @<:@default=no@:>@])],
[enable_extra_warning=yes],
[enable_extra_warning=no])

# Optimization/debugging flags
AC_ARG_VAR([COMPILEFLAGS], [Compiler flags for release versions])
AC_ARG_VAR([LINKFLAGS], [Linker flags for release versions])
Expand All @@ -738,36 +759,45 @@ AC_ARG_VAR([DEBUGLINKFLAGS], [Linker flags for debugging versions])
TOOL_LIBS=
DEBUGTOOL_LIBS=

# AX_HANDLE_EXTRA_WARNING(COMPILEFLAGS)
# -------------------------------------
AC_DEFUN([AX_HANDLE_EXTRA_WARNING],
[if test "x$enable_extra_warning" = xno; then
# Too many misleading indentation in the FORM source code.
AX_CHECK_COMPILE_FLAG([-Wno-misleading-indentation],
[$1="$$1 -Wno-misleading-indentation"])
# Too many false positives.
# See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88443
AX_CHECK_COMPILE_FLAG([-Wno-stringop-overflow],
[$1="$$1 -Wno-stringop-overflow"])
fi[]dnl
])

my_test_COMPILEFLAGS=${COMPILEFLAGS+set}
if test "$my_test_COMPILEFLAGS" != set; then
if test "x$vendor" = xgnu; then
# We don't use -pedantic option because of horrible warnings.
COMPILEFLAGS="-Wall -Wextra -Wpadded -O3"
COMPILEFLAGS="-Wall -Wextra -Wpadded"
AX_HANDLE_EXTRA_WARNING([COMPILEFLAGS])
# Enable optimizations.
COMPILEFLAGS="$COMPILEFLAGS -O3"
if test "x$enable_profile" != xgprof; then
# -pg conflicts with -fomit-frame-pointer.
COMPILEFLAGS="$COMPILEFLAGS -fomit-frame-pointer"
fi
if test "x$enable_native" = xyes; then
# Check for -march=native.
AC_MSG_CHECKING([whether compiler accepts -march=native])
ok=no
save_CFLAGS=$CFLAGS
CFLAGS="$CFLAGS -march=native"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [ok=yes])
CFLAGS=$save_CFLAGS
AC_MSG_RESULT($ok)
if test "x$ok" = xyes; then
COMPILEFLAGS="$COMPILEFLAGS -march=native"
else
if test "x$print_data_model" = xILP32; then
# Use -march=native if available.
AX_CHECK_COMPILE_FLAG([-march=native],
[COMPILEFLAGS="$COMPILEFLAGS -march=native"],
[if test "x$print_data_model" = xILP32; then
if test "x$print_cpu" = xPentium; then
# NOTE: In a strict sense, i686 must be used for Pentium Pro or later.
COMPILEFLAGS="$COMPILEFLAGS -march=i586"
elif test "x$print_cpu" = 'xPentium Pro'; then
COMPILEFLAGS="$COMPILEFLAGS -march=i686"
elif test "x$print_cpu" = xOpteron; then
COMPILEFLAGS="$COMPILEFLAGS -march=opteron"
fi
fi
fi
fi])
fi
# Profiling option.
if test "x$enable_profile" = xgprof; then
Expand Down Expand Up @@ -809,24 +839,18 @@ fi
my_test_DEBUGCOMPILEFLAGS=${DEBUGCOMPILEFLAGS+set}
if test "$my_test_DEBUGCOMPILEFLAGS" != set && test "x$enable_debug" = xyes; then
if test "x$vendor" = xgnu; then
DEBUGCOMPILEFLAGS='-g3 -Wall -Wextra'
DEBUGCOMPILEFLAGS='-Wall -Wextra'
if test "x$enable_sanitize" = xno; then
# UBSan puts many paddings (at least in gcc 5.3).
DEBUGCOMPILEFLAGS="$DEBUGCOMPILEFLAGS -Wpadded"
fi
# Check for -Og.
AC_MSG_CHECKING([whether compiler accepts -Og])
ok=no
save_CFLAGS=$CFLAGS
CFLAGS="$CFLAGS -Og"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [ok=yes])
CFLAGS=$save_CFLAGS
AC_MSG_RESULT($ok)
if test "x$ok" = xyes; then
DEBUGCOMPILEFLAGS="$DEBUGCOMPILEFLAGS -Og"
else
DEBUGCOMPILEFLAGS="$DEBUGCOMPILEFLAGS -O0"
fi
AX_HANDLE_EXTRA_WARNING([DEBUGCOMPILEFLAGS])
# Check for -Og. If it doesn't work then use -O0.
AX_CHECK_COMPILE_FLAG([-Og],
[DEBUGCOMPILEFLAGS="$DEBUGCOMPILEFLAGS -Og"],
[DEBUGCOMPILEFLAGS="$DEBUGCOMPILEFLAGS -O0"])
# Debugging information.
DEBUGCOMPILEFLAGS="$DEBUGCOMPILEFLAGS -g3"
# Coverage option.
if test "x$enable_coverage" = xyes; then
DEBUGCOMPILEFLAGS="$DEBUGCOMPILEFLAGS -coverage"
Expand All @@ -840,31 +864,13 @@ if test "$my_test_DEBUGCOMPILEFLAGS" != set && test "x$enable_debug" = xyes; the
else
tmp_sanitize=$enable_sanitize,$san
fi
AC_MSG_CHECKING([whether compiler accepts -fsanitize=$tmp_sanitize])
ok=no
save_CFLAGS=$CFLAGS
CFLAGS="$CFLAGS -fsanitize=$tmp_sanitize"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [ok=yes])
CFLAGS=$save_CFLAGS
AC_MSG_RESULT($ok)
if test "x$ok" = xyes; then
enable_sanitize=$tmp_sanitize
fi
AX_CHECK_COMPILE_FLAG([-fsanitize=$tmp_sanitize], [enable_sanitize=$tmp_sanitize])
done
if test "x$enable_sanitize" = x; then
enable_sanitize=failed
fi
elif test "x$enable_sanitize" != xno; then
AC_MSG_CHECKING([whether compiler accepts -fsanitize=$enable_sanitize])
ok=no
save_CFLAGS=$CFLAGS
CFLAGS="$CFLAGS -fsanitize=$enable_sanitize"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [ok=yes])
CFLAGS=$save_CFLAGS
AC_MSG_RESULT($ok)
if test "x$ok" != xyes; then
enable_sanitize=failed
fi
AX_CHECK_COMPILE_FLAG([-fsanitize=$enable_sanitize], [], [enable_sanitize=failed])
fi
if test "x$enable_sanitize" = xfailed; then
AC_MSG_FAILURE([test for sanitizer failed. Give --disable-sanitize if you want to compile without sanitizer])
Expand Down
74 changes: 74 additions & 0 deletions m4/ax_check_compile_flag.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# ===========================================================================
# http://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html
# ===========================================================================
#
# SYNOPSIS
#
# AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT])
#
# DESCRIPTION
#
# Check whether the given FLAG works with the current language's compiler
# or gives an error. (Warnings, however, are ignored)
#
# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
# success/failure.
#
# If EXTRA-FLAGS is defined, it is added to the current language's default
# flags (e.g. CFLAGS) when the check is done. The check is thus made with
# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to
# force the compiler to issue an error when a bad flag is given.
#
# INPUT gives an alternative input source to AC_COMPILE_IFELSE.
#
# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this
# macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG.
#
# LICENSE
#
# Copyright (c) 2008 Guido U. Draheim <[email protected]>
# Copyright (c) 2011 Maarten Bosmans <[email protected]>
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
# As a special exception, the respective Autoconf Macro's copyright owner
# gives unlimited permission to copy, distribute and modify the configure
# scripts that are the output of Autoconf when processing the Macro. You
# need not follow the terms of the GNU General Public License when using
# or distributing such scripts, even though portions of the text of the
# Macro appear in them. The GNU General Public License (GPL) does govern
# all other use of the material that constitutes the Autoconf Macro.
#
# This special exception to the GPL applies to versions of the Autoconf
# Macro released by the Autoconf Archive. When you make and distribute a
# modified version of the Autoconf Macro, you may extend this special
# exception to the GPL to apply to your modified version as well.

#serial 3

AC_DEFUN([AX_CHECK_COMPILE_FLAG],
[AC_PREREQ(2.59)dnl for _AC_LANG_PREFIX
AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl
AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [
ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
_AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1"
AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
[AS_VAR_SET(CACHEVAR,[yes])],
[AS_VAR_SET(CACHEVAR,[no])])
_AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags])
AS_IF([test x"AS_VAR_GET(CACHEVAR)" = xyes],
[m4_default([$2], :)],
[m4_default([$3], :)])
AS_VAR_POPDEF([CACHEVAR])dnl
])dnl AX_CHECK_COMPILE_FLAGS

0 comments on commit d5f9d33

Please sign in to comment.