FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-30104: Use -fno-strict-aliasing on clang (#1376) (#1377) · python/cpython@03a7ab7 · GitHub

Repository navigation

Commit 03a7ab7

Browse files
authored
bpo-30104: Use -fno-strict-aliasing on clang (#1376) (#1377)
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 (cherry picked from commit 809101f)
1 parent e37d163 commit 03a7ab7

3 files changed

Lines changed: 64 additions & 14 deletions

File tree

‎Makefile.pre.in‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ ARFLAGS= @ARFLAGS@
103103
CFLAGSFORSHARED=@CFLAGSFORSHARED@
104104
# C flags used for building the interpreter object files
105105
PY_CORE_CFLAGS= $(PY_CFLAGS) $(PY_CFLAGS_NODIST) $(PY_CPPFLAGS) $(CFLAGSFORSHARED) -DPy_BUILD_CORE
106+
# Strict or non-strict aliasing flags used to compile dtoa.c, see above
107+
CFLAGS_ALIASING=@CFLAGS_ALIASING@
106108

107109

108110
# Machine-dependent subdirectories
@@ -1532,6 +1534,13 @@ config.status: $(srcdir)/configure
15321534
.c.o:
15331535
$(CC) -c $(PY_CORE_CFLAGS) -o $@ $<
15341536

1537+
# bpo-30104: dtoa.c uses union to cast double to unsigned long[2]. clang 4.0
1538+
# with -O2 or higher and strict aliasing miscompiles the ratio() function
1539+
# causing rounding issues. Compile dtoa.c using -fno-strict-aliasing on clang.
1540+
# https://bugs.llvm.org//show_bug.cgi?id=31928
1541+
Python/dtoa.o: Python/dtoa.c
1542+
$(CC) -c $(PY_CORE_CFLAGS) $(CFLAGS_ALIASING) -o $@ $<
1543+
15351544
# Run reindent on the library
15361545
reindent:
15371546
./$(BUILDPYTHON) $(srcdir)/Tools/scripts/reindent.py -r $(srcdir)/Lib

‎configure‎

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,7 @@ OTHER_LIBTOOL_OPT
666666
UNIVERSAL_ARCH_FLAGS
667667
CFLAGS_NODIST
668668
BASECFLAGS
669+
CFLAGS_ALIASING
669670
OPT
670671
LLVM_PROF_FOUND
671672
target_os
@@ -6859,6 +6860,7 @@ esac
68596860
# tweak OPT based on compiler and platform, only if the user didn't set
68606861
# it on the command line
68616862

6863+
68626864
if test "${OPT-unset}" = "unset"
68636865
then
68646866
case $GCC in
@@ -6871,30 +6873,49 @@ then
68716873
WRAP="-fwrapv"
68726874
fi
68736875

6874-
# Clang also needs -fwrapv
68756876
case $CC in
6876-
*clang*) WRAP="-fwrapv"
6877-
;;
6877+
*clang*)
6878+
cc_is_clang=1
6879+
;;
6880+
*)
6881+
if $CC --version 2>&1 | grep -q clang
6882+
then
6883+
cc_is_clang=1
6884+
else
6885+
cc_is_clang=
6886+
fi
68786887
esac
68796888

6889+
if test -n "${cc_is_clang}"
6890+
then
6891+
# Clang also needs -fwrapv
6892+
WRAP="-fwrapv"
6893+
# bpo-30104: disable strict aliasing to compile correctly dtoa.c,
6894+
# see Makefile.pre.in for more information
6895+
CFLAGS_ALIASING="-fno-strict-aliasing"
6896+
fi
6897+
68806898
case $ac_cv_prog_cc_g in
68816899
yes)
68826900
if test "$Py_DEBUG" = 'true' ; then
68836901
# Optimization messes up debuggers, so turn it off for
68846902
# debug builds.
68856903
if "$CC" -v --help 2>/dev/null |grep -- -Og > /dev/null; then
6886-
OPT="-g -Og -Wall $STRICT_PROTO"
6904+
OPT="-g -Og -Wall"
68876905
else
6888-
OPT="-g -O0 -Wall $STRICT_PROTO"
6906+
OPT="-g -O0 -Wall"
68896907
fi
68906908
else
6891-
OPT="-g $WRAP -O3 -Wall $STRICT_PROTO"
6909+
OPT="-g $WRAP -O3 -Wall"
68926910
fi
68936911
;;
68946912
*)
6895-
OPT="-O3 -Wall $STRICT_PROTO"
6913+
OPT="-O3 -Wall"
68966914
;;
68976915
esac
6916+
6917+
OPT="$OPT $STRICT_PROTO"
6918+
68986919
case $ac_sys_system in
68996920
SCO_SV*) OPT="$OPT -m486 -DSCO5"
69006921
;;

‎configure.ac‎

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,7 @@ esac
14031403
# tweak OPT based on compiler and platform, only if the user didn't set
14041404
# it on the command line
14051405
AC_SUBST(OPT)
1406+
AC_SUBST(CFLAGS_ALIASING)
14061407
if test "${OPT-unset}" = "unset"
14071408
then
14081409
case $GCC in
@@ -1415,30 +1416,49 @@ then
14151416
WRAP="-fwrapv"
14161417
fi
14171418

1418-
# Clang also needs -fwrapv
14191419
case $CC in
1420-
*clang*) WRAP="-fwrapv"
1421-
;;
1420+
*clang*)
1421+
cc_is_clang=1
1422+
;;
1423+
*)
1424+
if $CC --version 2>&1 | grep -q clang
1425+
then
1426+
cc_is_clang=1
1427+
else
1428+
cc_is_clang=
1429+
fi
14221430
esac
14231431

1432+
if test -n "${cc_is_clang}"
1433+
then
1434+
# Clang also needs -fwrapv
1435+
WRAP="-fwrapv"
1436+
# bpo-30104: disable strict aliasing to compile correctly dtoa.c,
1437+
# see Makefile.pre.in for more information
1438+
CFLAGS_ALIASING="-fno-strict-aliasing"
1439+
fi
1440+
14241441
case $ac_cv_prog_cc_g in
14251442
yes)
14261443
if test "$Py_DEBUG" = 'true' ; then
14271444
# Optimization messes up debuggers, so turn it off for
14281445
# debug builds.
14291446
if "$CC" -v --help 2>/dev/null |grep -- -Og > /dev/null; then
1430-
OPT="-g -Og -Wall $STRICT_PROTO"
1447+
OPT="-g -Og -Wall"
14311448
else
1432-
OPT="-g -O0 -Wall $STRICT_PROTO"
1449+
OPT="-g -O0 -Wall"
14331450
fi
14341451
else
1435-
OPT="-g $WRAP -O3 -Wall $STRICT_PROTO"
1452+
OPT="-g $WRAP -O3 -Wall"
14361453
fi
14371454
;;
14381455
*)
1439-
OPT="-O3 -Wall $STRICT_PROTO"
1456+
OPT="-O3 -Wall"
14401457
;;
14411458
esac
1459+
1460+
OPT="$OPT $STRICT_PROTO"
1461+
14421462
case $ac_sys_system in
14431463
SCO_SV*) OPT="$OPT -m486 -DSCO5"
14441464
;;

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL