summaryrefslogtreecommitdiffstats
path: root/configure.ac
diff options
context:
space:
mode:
authorMatthias Görgens <matthias.goergens@gmail.com>2023-03-04 21:39:52 (GMT)
committerGitHub <noreply@github.com>2023-03-04 21:39:52 (GMT)
commiteff9f43924fc836970b2378d58523388d9246194 (patch)
treef2461f074163219b36312dd12e0cdfbfbe323d1f /configure.ac
parente4609cbe4ca2d3d4fc07c19a7d0bdec52f054c63 (diff)
downloadcpython-eff9f43924fc836970b2378d58523388d9246194.zip
cpython-eff9f43924fc836970b2378d58523388d9246194.tar.gz
cpython-eff9f43924fc836970b2378d58523388d9246194.tar.bz2
gh-96821: Add config option `--with-strict-overflow` (#96823)
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM> Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com> Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Co-authored-by: Shantanu <hauntsaninja@gmail.com>
Diffstat (limited to 'configure.ac')
-rw-r--r--configure.ac54
1 files changed, 45 insertions, 9 deletions
diff --git a/configure.ac b/configure.ac
index 982f669..31b7a21 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2073,6 +2073,45 @@ case $CC in
fi
esac
+dnl Historically, some of our code assumed that signed integer overflow
+dnl is defined behaviour via twos-complement.
+dnl Set STRICT_OVERFLOW_CFLAGS and NO_STRICT_OVERFLOW_CFLAGS depending on compiler support.
+dnl Pass the latter to modules that depend on such behaviour.
+_SAVE_VAR([CFLAGS])
+CFLAGS="-fstrict-overflow -fno-strict-overflow"
+AC_CACHE_CHECK([if $CC supports -fstrict-overflow and -fno-strict-overflow],
+ [ac_cv_cc_supports_fstrict_overflow],
+ AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM([[]], [[]])],
+ [ac_cv_cc_supports_fstrict_overflow=yes],
+ [ac_cv_cc_supports_fstrict_overflow=no]
+ )
+)
+_RESTORE_VAR([CFLAGS])
+
+AS_VAR_IF([ac_cv_cc_supports_fstrict_overflow], [yes],
+ [STRICT_OVERFLOW_CFLAGS="-fstrict-overflow"
+ NO_STRICT_OVERFLOW_CFLAGS="-fno-strict-overflow"],
+ [STRICT_OVERFLOW_CFLAGS=""
+ NO_STRICT_OVERFLOW_CFLAGS=""])
+
+AC_MSG_CHECKING([for --with-strict-overflow])
+AC_ARG_WITH([strict-overflow],
+ AS_HELP_STRING(
+ [--with-strict-overflow],
+ [if 'yes', add -fstrict-overflow to CFLAGS, else add -fno-strict-overflow (default is no)]
+ ),
+ [
+ AS_VAR_IF(
+ [ac_cv_cc_supports_fstrict_overflow], [no],
+ [AC_MSG_WARN([--with-strict-overflow=yes requires a compiler that supports -fstrict-overflow])],
+ []
+ )
+ ],
+ [with_strict_overflow=no]
+)
+AC_MSG_RESULT([$with_strict_overflow])
+
# Check if CC supports -Og optimization level
_SAVE_VAR([CFLAGS])
CFLAGS="-Og"
@@ -2103,15 +2142,8 @@ if test "${OPT-unset}" = "unset"
then
case $GCC in
yes)
- # For gcc 4.x we need to use -fwrapv so lets check if its supported
- if "$CC" -v --help 2>/dev/null |grep -- -fwrapv > /dev/null; then
- WRAP="-fwrapv"
- fi
-
if test -n "${cc_is_clang}"
then
- # Clang also needs -fwrapv
- WRAP="-fwrapv"
# bpo-30104: disable strict aliasing to compile correctly dtoa.c,
# see Makefile.pre.in for more information
CFLAGS_ALIASING="-fno-strict-aliasing"
@@ -2122,7 +2154,7 @@ then
if test "$Py_DEBUG" = 'true' ; then
OPT="-g $PYDEBUG_CFLAGS -Wall"
else
- OPT="-g $WRAP -O3 -Wall"
+ OPT="-g -O3 -Wall"
fi
;;
*)
@@ -2237,6 +2269,10 @@ AC_DEFUN([PY_CHECK_CC_WARNING], [
])
# tweak BASECFLAGS based on compiler and platform
+AS_VAR_IF([with_strict_overflow], [yes],
+ [BASECFLAGS="$BASECFLAGS $STRICT_OVERFLOW_CFLAGS"],
+ [BASECFLAGS="$BASECFLAGS $NO_STRICT_OVERFLOW_CFLAGS"])
+
case $GCC in
yes)
CFLAGS_NODIST="$CFLAGS_NODIST -std=c11"
@@ -7213,7 +7249,7 @@ PY_STDLIB_MOD([_crypt],
[$LIBCRYPT_CFLAGS], [$LIBCRYPT_LIBS])
PY_STDLIB_MOD([_ctypes],
[], [test "$have_libffi" = yes],
- [$LIBFFI_CFLAGS], [$LIBFFI_LIBS])
+ [$NO_STRICT_OVERFLOW_CFLAGS $LIBFFI_CFLAGS], [$LIBFFI_LIBS])
PY_STDLIB_MOD([_curses],
[], [test "$have_curses" != "no"],
[$CURSES_CFLAGS], [$CURSES_LIBS]