@@ -2073,6 +2073,45 @@ case $CC in
2073
2073
fi
2074
2074
esac
2075
2075
2076
+ dnl Historically, some of our code assumed that signed integer overflow
2077
+ dnl is defined behaviour via twos-complement.
2078
+ dnl Set STRICT_OVERFLOW_CFLAGS and NO_STRICT_OVERFLOW_CFLAGS depending on compiler support.
2079
+ dnl Pass the latter to modules that depend on such behaviour.
2080
+ _SAVE_VAR([ CFLAGS] )
2081
+ CFLAGS="-fstrict-overflow -fno-strict-overflow"
2082
+ AC_CACHE_CHECK ( [ if $CC supports -fstrict-overflow and -fno-strict-overflow] ,
2083
+ [ ac_cv_cc_supports_fstrict_overflow] ,
2084
+ AC_COMPILE_IFELSE (
2085
+ [ AC_LANG_PROGRAM ( [ [ ] ] , [ [ ] ] ) ] ,
2086
+ [ ac_cv_cc_supports_fstrict_overflow=yes] ,
2087
+ [ ac_cv_cc_supports_fstrict_overflow=no]
2088
+ )
2089
+ )
2090
+ _RESTORE_VAR([ CFLAGS] )
2091
+
2092
+ AS_VAR_IF ( [ ac_cv_cc_supports_fstrict_overflow] , [ yes] ,
2093
+ [ STRICT_OVERFLOW_CFLAGS="-fstrict-overflow"
2094
+ NO_STRICT_OVERFLOW_CFLAGS="-fno-strict-overflow"] ,
2095
+ [ STRICT_OVERFLOW_CFLAGS=""
2096
+ NO_STRICT_OVERFLOW_CFLAGS=""] )
2097
+
2098
+ AC_MSG_CHECKING ( [ for --with-strict-overflow] )
2099
+ AC_ARG_WITH ( [ strict-overflow] ,
2100
+ AS_HELP_STRING (
2101
+ [ --with-strict-overflow] ,
2102
+ [ if 'yes', add -fstrict-overflow to CFLAGS, else add -fno-strict-overflow (default is no)]
2103
+ ) ,
2104
+ [
2105
+ AS_VAR_IF (
2106
+ [ ac_cv_cc_supports_fstrict_overflow] , [ no] ,
2107
+ [ AC_MSG_WARN ( [ --with-strict-overflow=yes requires a compiler that supports -fstrict-overflow] ) ] ,
2108
+ [ ]
2109
+ )
2110
+ ] ,
2111
+ [ with_strict_overflow=no]
2112
+ )
2113
+ AC_MSG_RESULT ( [ $with_strict_overflow] )
2114
+
2076
2115
# Check if CC supports -Og optimization level
2077
2116
_SAVE_VAR([ CFLAGS] )
2078
2117
CFLAGS="-Og"
@@ -2103,15 +2142,8 @@ if test "${OPT-unset}" = "unset"
2103
2142
then
2104
2143
case $GCC in
2105
2144
yes)
2106
- # For gcc 4.x we need to use -fwrapv so lets check if its supported
2107
- if "$CC" -v --help 2>/dev/null |grep -- -fwrapv > /dev/null; then
2108
- WRAP="-fwrapv"
2109
- fi
2110
-
2111
2145
if test -n "${cc_is_clang}"
2112
2146
then
2113
- # Clang also needs -fwrapv
2114
- WRAP="-fwrapv"
2115
2147
# bpo-30104: disable strict aliasing to compile correctly dtoa.c,
2116
2148
# see Makefile.pre.in for more information
2117
2149
CFLAGS_ALIASING="-fno-strict-aliasing"
@@ -2122,7 +2154,7 @@ then
2122
2154
if test "$Py_DEBUG" = 'true' ; then
2123
2155
OPT="-g $PYDEBUG_CFLAGS -Wall"
2124
2156
else
2125
- OPT="-g $WRAP -O3 -Wall"
2157
+ OPT="-g -O3 -Wall"
2126
2158
fi
2127
2159
;;
2128
2160
*)
@@ -2237,6 +2269,10 @@ AC_DEFUN([PY_CHECK_CC_WARNING], [
2237
2269
] )
2238
2270
2239
2271
# tweak BASECFLAGS based on compiler and platform
2272
+ AS_VAR_IF ( [ with_strict_overflow] , [ yes] ,
2273
+ [ BASECFLAGS="$BASECFLAGS $STRICT_OVERFLOW_CFLAGS"] ,
2274
+ [ BASECFLAGS="$BASECFLAGS $NO_STRICT_OVERFLOW_CFLAGS"] )
2275
+
2240
2276
case $GCC in
2241
2277
yes)
2242
2278
CFLAGS_NODIST="$CFLAGS_NODIST -std=c11"
@@ -7213,7 +7249,7 @@ PY_STDLIB_MOD([_crypt],
7213
7249
[ $LIBCRYPT_CFLAGS] , [ $LIBCRYPT_LIBS] )
7214
7250
PY_STDLIB_MOD([ _ctypes] ,
7215
7251
[ ] , [ test "$have_libffi" = yes] ,
7216
- [ $LIBFFI_CFLAGS] , [ $LIBFFI_LIBS] )
7252
+ [ $NO_STRICT_OVERFLOW_CFLAGS $ LIBFFI_CFLAGS] , [ $LIBFFI_LIBS] )
7217
7253
PY_STDLIB_MOD([ _curses] ,
7218
7254
[ ] , [ test "$have_curses" != "no"] ,
7219
7255
[ $CURSES_CFLAGS] , [ $CURSES_LIBS]
0 commit comments