File tree Expand file tree Collapse file tree 3 files changed +17
-16
lines changed
Expand file tree Collapse file tree 3 files changed +17
-16
lines changed Original file line number Diff line number Diff line change @@ -107,6 +107,8 @@ ARFLAGS= @ARFLAGS@
107107CFLAGSFORSHARED=@CFLAGSFORSHARED@
108108# C flags used for building the interpreter object files
109109PY_CORE_CFLAGS= $(PY_CFLAGS) $(PY_CFLAGS_NODIST) $(PY_CPPFLAGS) $(CFLAGSFORSHARED) -DPy_BUILD_CORE
110+ # Strict or non-strict aliasing flags used to compile dtoa.c, see above
111+ CFLAGS_ALIASING=@CFLAGS_ALIASING@
110112
111113
112114# Machine-dependent subdirectories
@@ -1536,6 +1538,13 @@ config.status: $(srcdir)/configure
15361538.c.o:
15371539 $(CC) -c $(PY_CORE_CFLAGS) -o $@ $<
15381540
1541+ # bpo-30104: dtoa.c uses union to cast double to unsigned long[2]. clang 4.0
1542+ # with -O2 or higher and strict aliasing miscompiles the ratio() function
1543+ # causing rounding issues. Compile dtoa.c using -fno-strict-aliasing on clang.
1544+ # https://bugs.llvm.org//show_bug.cgi?id=31928
1545+ Python/dtoa.o: Python/dtoa.c
1546+ $(CC) -c $(PY_CORE_CFLAGS) $(CFLAGS_ALIASING) -o $@ $<
1547+
15391548# Run reindent on the library
15401549reindent:
15411550 ./$(BUILDPYTHON) $(srcdir)/Tools/scripts/reindent.py -r $(srcdir)/Lib
Original file line number Diff line number Diff line change @@ -668,6 +668,7 @@ OTHER_LIBTOOL_OPT
668668UNIVERSAL_ARCH_FLAGS
669669CFLAGS_NODIST
670670BASECFLAGS
671+ CFLAGS_ALIASING
671672OPT
672673LLVM_PROF_FOUND
673674target_os
@@ -6829,13 +6830,7 @@ then
68296830 then
68306831 # Clang also needs -fwrapv
68316832 WRAP=" -fwrapv"
6832-
6833- # bpo-30104: Python/dtoa.c requires to be build with
6834- # -fno-strict-aliasing to fix compiler issue on the
6835- # double/ULong[2] union using clang 4.0 and optimization level
6836- # -O2 or higher
6837- # https://bugs.llvm.org//show_bug.cgi?id=31928
6838- ALIASING=" -fno-strict-aliasing"
6833+ CFLAGS_ALIASING=" -fno-strict-aliasing"
68396834 fi
68406835
68416836 case $ac_cv_prog_cc_g in
@@ -6857,7 +6852,7 @@ then
68576852 ;;
68586853 esac
68596854
6860- OPT=" $OPT $STRICT_PROTO $ALIASING "
6855+ OPT=" $OPT $STRICT_PROTO "
68616856
68626857 case $ac_sys_system in
68636858 SCO_SV* ) OPT=" $OPT -m486 -DSCO5"
Original file line number Diff line number Diff line change @@ -1440,6 +1440,7 @@ esac
14401440# tweak OPT based on compiler and platform, only if the user didn't set
14411441# it on the command line
14421442AC_SUBST ( OPT )
1443+ AC_SUBST ( CFLAGS_ALIASING )
14431444if test "${OPT-unset}" = "unset"
14441445then
14451446 case $GCC in
@@ -1469,13 +1470,9 @@ then
14691470 then
14701471 # Clang also needs -fwrapv
14711472 WRAP="-fwrapv"
1472-
1473- # bpo-30104: Python/dtoa.c requires to be build with
1474- # -fno-strict-aliasing to fix compiler issue on the
1475- # double/ULong[2] union using clang 4.0 and optimization level
1476- # -O2 or higher
1477- # https://bugs.llvm.org//show_bug.cgi?id=31928
1478- ALIASING="-fno-strict-aliasing"
1473+ # bpo-30104: disable strict aliasing to compile correctly dtoa.c,
1474+ # see Makefile.pre.in for more information
1475+ CFLAGS_ALIASING="-fno-strict-aliasing"
14791476 fi
14801477
14811478 case $ac_cv_prog_cc_g in
@@ -1497,7 +1494,7 @@ then
14971494 ;;
14981495 esac
14991496
1500- OPT="$OPT $STRICT_PROTO $ALIASING "
1497+ OPT="$OPT $STRICT_PROTO"
15011498
15021499 case $ac_sys_system in
15031500 SCO_SV*) OPT="$OPT -m486 -DSCO5"
You can’t perform that action at this time.
0 commit comments