mirror of
https://github.com/python/cpython.git
synced 2025-09-30 12:21:51 +00:00
bpo-30104: Use -fno-strict-aliasing on clang (#1376)
Python/dtoa.c is not compiled correctly with clang 4.0 and optimization level -O2 or higher, because of an aliasing issue on the double/ULong[2] union. Only compile dtoa.c with -fno-strict-aliasing. LLVM bug report: https://bugs.llvm.org//show_bug.cgi?id=31928
This commit is contained in:
parent
78b23ab682
commit
809101f14f
3 changed files with 64 additions and 14 deletions
|
@ -107,6 +107,8 @@ ARFLAGS= @ARFLAGS@
|
||||||
CFLAGSFORSHARED=@CFLAGSFORSHARED@
|
CFLAGSFORSHARED=@CFLAGSFORSHARED@
|
||||||
# C flags used for building the interpreter object files
|
# C flags used for building the interpreter object files
|
||||||
PY_CORE_CFLAGS= $(PY_CFLAGS) $(PY_CFLAGS_NODIST) $(PY_CPPFLAGS) $(CFLAGSFORSHARED) -DPy_BUILD_CORE
|
PY_CORE_CFLAGS= $(PY_CFLAGS) $(PY_CFLAGS_NODIST) $(PY_CPPFLAGS) $(CFLAGSFORSHARED) -DPy_BUILD_CORE
|
||||||
|
# Strict or non-strict aliasing flags used to compile dtoa.c, see above
|
||||||
|
CFLAGS_ALIASING=@CFLAGS_ALIASING@
|
||||||
|
|
||||||
|
|
||||||
# Machine-dependent subdirectories
|
# Machine-dependent subdirectories
|
||||||
|
@ -1535,6 +1537,13 @@ config.status: $(srcdir)/configure
|
||||||
.c.o:
|
.c.o:
|
||||||
$(CC) -c $(PY_CORE_CFLAGS) -o $@ $<
|
$(CC) -c $(PY_CORE_CFLAGS) -o $@ $<
|
||||||
|
|
||||||
|
# bpo-30104: dtoa.c uses union to cast double to unsigned long[2]. clang 4.0
|
||||||
|
# with -O2 or higher and strict aliasing miscompiles the ratio() function
|
||||||
|
# causing rounding issues. Compile dtoa.c using -fno-strict-aliasing on clang.
|
||||||
|
# https://bugs.llvm.org//show_bug.cgi?id=31928
|
||||||
|
Python/dtoa.o: Python/dtoa.c
|
||||||
|
$(CC) -c $(PY_CORE_CFLAGS) $(CFLAGS_ALIASING) -o $@ $<
|
||||||
|
|
||||||
# Run reindent on the library
|
# Run reindent on the library
|
||||||
reindent:
|
reindent:
|
||||||
./$(BUILDPYTHON) $(srcdir)/Tools/scripts/reindent.py -r $(srcdir)/Lib
|
./$(BUILDPYTHON) $(srcdir)/Tools/scripts/reindent.py -r $(srcdir)/Lib
|
||||||
|
|
35
configure
vendored
35
configure
vendored
|
@ -668,6 +668,7 @@ OTHER_LIBTOOL_OPT
|
||||||
UNIVERSAL_ARCH_FLAGS
|
UNIVERSAL_ARCH_FLAGS
|
||||||
CFLAGS_NODIST
|
CFLAGS_NODIST
|
||||||
BASECFLAGS
|
BASECFLAGS
|
||||||
|
CFLAGS_ALIASING
|
||||||
OPT
|
OPT
|
||||||
LLVM_PROF_FOUND
|
LLVM_PROF_FOUND
|
||||||
target_os
|
target_os
|
||||||
|
@ -6851,6 +6852,7 @@ esac
|
||||||
# tweak OPT based on compiler and platform, only if the user didn't set
|
# tweak OPT based on compiler and platform, only if the user didn't set
|
||||||
# it on the command line
|
# it on the command line
|
||||||
|
|
||||||
|
|
||||||
if test "${OPT-unset}" = "unset"
|
if test "${OPT-unset}" = "unset"
|
||||||
then
|
then
|
||||||
case $GCC in
|
case $GCC in
|
||||||
|
@ -6863,30 +6865,49 @@ then
|
||||||
WRAP="-fwrapv"
|
WRAP="-fwrapv"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Clang also needs -fwrapv
|
|
||||||
case $CC in
|
case $CC in
|
||||||
*clang*) WRAP="-fwrapv"
|
*clang*)
|
||||||
;;
|
cc_is_clang=1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
if $CC --version 2>&1 | grep -q clang
|
||||||
|
then
|
||||||
|
cc_is_clang=1
|
||||||
|
else
|
||||||
|
cc_is_clang=
|
||||||
|
fi
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
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"
|
||||||
|
fi
|
||||||
|
|
||||||
case $ac_cv_prog_cc_g in
|
case $ac_cv_prog_cc_g in
|
||||||
yes)
|
yes)
|
||||||
if test "$Py_DEBUG" = 'true' ; then
|
if test "$Py_DEBUG" = 'true' ; then
|
||||||
# Optimization messes up debuggers, so turn it off for
|
# Optimization messes up debuggers, so turn it off for
|
||||||
# debug builds.
|
# debug builds.
|
||||||
if "$CC" -v --help 2>/dev/null |grep -- -Og > /dev/null; then
|
if "$CC" -v --help 2>/dev/null |grep -- -Og > /dev/null; then
|
||||||
OPT="-g -Og -Wall $STRICT_PROTO"
|
OPT="-g -Og -Wall"
|
||||||
else
|
else
|
||||||
OPT="-g -O0 -Wall $STRICT_PROTO"
|
OPT="-g -O0 -Wall"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
OPT="-g $WRAP -O3 -Wall $STRICT_PROTO"
|
OPT="-g $WRAP -O3 -Wall"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
OPT="-O3 -Wall $STRICT_PROTO"
|
OPT="-O3 -Wall"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
OPT="$OPT $STRICT_PROTO"
|
||||||
|
|
||||||
case $ac_sys_system in
|
case $ac_sys_system in
|
||||||
SCO_SV*) OPT="$OPT -m486 -DSCO5"
|
SCO_SV*) OPT="$OPT -m486 -DSCO5"
|
||||||
;;
|
;;
|
||||||
|
|
34
configure.ac
34
configure.ac
|
@ -1447,6 +1447,7 @@ esac
|
||||||
# tweak OPT based on compiler and platform, only if the user didn't set
|
# tweak OPT based on compiler and platform, only if the user didn't set
|
||||||
# it on the command line
|
# it on the command line
|
||||||
AC_SUBST(OPT)
|
AC_SUBST(OPT)
|
||||||
|
AC_SUBST(CFLAGS_ALIASING)
|
||||||
if test "${OPT-unset}" = "unset"
|
if test "${OPT-unset}" = "unset"
|
||||||
then
|
then
|
||||||
case $GCC in
|
case $GCC in
|
||||||
|
@ -1459,30 +1460,49 @@ then
|
||||||
WRAP="-fwrapv"
|
WRAP="-fwrapv"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Clang also needs -fwrapv
|
|
||||||
case $CC in
|
case $CC in
|
||||||
*clang*) WRAP="-fwrapv"
|
*clang*)
|
||||||
;;
|
cc_is_clang=1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
if $CC --version 2>&1 | grep -q clang
|
||||||
|
then
|
||||||
|
cc_is_clang=1
|
||||||
|
else
|
||||||
|
cc_is_clang=
|
||||||
|
fi
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
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"
|
||||||
|
fi
|
||||||
|
|
||||||
case $ac_cv_prog_cc_g in
|
case $ac_cv_prog_cc_g in
|
||||||
yes)
|
yes)
|
||||||
if test "$Py_DEBUG" = 'true' ; then
|
if test "$Py_DEBUG" = 'true' ; then
|
||||||
# Optimization messes up debuggers, so turn it off for
|
# Optimization messes up debuggers, so turn it off for
|
||||||
# debug builds.
|
# debug builds.
|
||||||
if "$CC" -v --help 2>/dev/null |grep -- -Og > /dev/null; then
|
if "$CC" -v --help 2>/dev/null |grep -- -Og > /dev/null; then
|
||||||
OPT="-g -Og -Wall $STRICT_PROTO"
|
OPT="-g -Og -Wall"
|
||||||
else
|
else
|
||||||
OPT="-g -O0 -Wall $STRICT_PROTO"
|
OPT="-g -O0 -Wall"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
OPT="-g $WRAP -O3 -Wall $STRICT_PROTO"
|
OPT="-g $WRAP -O3 -Wall"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
OPT="-O3 -Wall $STRICT_PROTO"
|
OPT="-O3 -Wall"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
OPT="$OPT $STRICT_PROTO"
|
||||||
|
|
||||||
case $ac_sys_system in
|
case $ac_sys_system in
|
||||||
SCO_SV*) OPT="$OPT -m486 -DSCO5"
|
SCO_SV*) OPT="$OPT -m486 -DSCO5"
|
||||||
;;
|
;;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue