Skip to content

Commit 28205b2

Browse files
authored
bpo-30104: Use -fno-strict-aliasing on clang (python#1221)
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. LLVM bug report: https://bugs.llvm.org//show_bug.cgi?id=31928
1 parent 791dc83 commit 28205b2

2 files changed

Lines changed: 32 additions & 12 deletions

File tree

configure

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6814,8 +6814,15 @@ then
68146814

68156815
# Clang also needs -fwrapv
68166816
case $CC in
6817-
*clang*) WRAP="-fwrapv"
6818-
;;
6817+
*clang*)
6818+
WRAP="-fwrapv"
6819+
# bpo-30104: Python/dtoa.c requires to be build with
6820+
# -fno-strict-aliasing to fix compiler issue on the
6821+
# double/ULong[2] union using clang 4.0 and optimization level
6822+
# -O2 or higher
6823+
# https://bugs.llvm.org//show_bug.cgi?id=31928
6824+
ALIASING="-fno-strict-aliasing"
6825+
;;
68196826
esac
68206827

68216828
case $ac_cv_prog_cc_g in
@@ -6824,18 +6831,21 @@ then
68246831
# Optimization messes up debuggers, so turn it off for
68256832
# debug builds.
68266833
if "$CC" -v --help 2>/dev/null |grep -- -Og > /dev/null; then
6827-
OPT="-g -Og -Wall $STRICT_PROTO"
6834+
OPT="-g -Og -Wall"
68286835
else
6829-
OPT="-g -O0 -Wall $STRICT_PROTO"
6836+
OPT="-g -O0 -Wall"
68306837
fi
68316838
else
6832-
OPT="-g $WRAP -O3 -Wall $STRICT_PROTO"
6839+
OPT="-g $WRAP -O3 -Wall"
68336840
fi
68346841
;;
68356842
*)
6836-
OPT="-O3 -Wall $STRICT_PROTO"
6843+
OPT="-O3 -Wall"
68376844
;;
68386845
esac
6846+
6847+
OPT="$OPT $STRICT_PROTO $ALIASING"
6848+
68396849
case $ac_sys_system in
68406850
SCO_SV*) OPT="$OPT -m486 -DSCO5"
68416851
;;

configure.ac

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,8 +1454,15 @@ then
14541454

14551455
# Clang also needs -fwrapv
14561456
case $CC in
1457-
*clang*) WRAP="-fwrapv"
1458-
;;
1457+
*clang*)
1458+
WRAP="-fwrapv"
1459+
# bpo-30104: Python/dtoa.c requires to be build with
1460+
# -fno-strict-aliasing to fix compiler issue on the
1461+
# double/ULong[2] union using clang 4.0 and optimization level
1462+
# -O2 or higher
1463+
# https://bugs.llvm.org//show_bug.cgi?id=31928
1464+
ALIASING="-fno-strict-aliasing"
1465+
;;
14591466
esac
14601467

14611468
case $ac_cv_prog_cc_g in
@@ -1464,18 +1471,21 @@ then
14641471
# Optimization messes up debuggers, so turn it off for
14651472
# debug builds.
14661473
if "$CC" -v --help 2>/dev/null |grep -- -Og > /dev/null; then
1467-
OPT="-g -Og -Wall $STRICT_PROTO"
1474+
OPT="-g -Og -Wall"
14681475
else
1469-
OPT="-g -O0 -Wall $STRICT_PROTO"
1476+
OPT="-g -O0 -Wall"
14701477
fi
14711478
else
1472-
OPT="-g $WRAP -O3 -Wall $STRICT_PROTO"
1479+
OPT="-g $WRAP -O3 -Wall"
14731480
fi
14741481
;;
14751482
*)
1476-
OPT="-O3 -Wall $STRICT_PROTO"
1483+
OPT="-O3 -Wall"
14771484
;;
14781485
esac
1486+
1487+
OPT="$OPT $STRICT_PROTO $ALIASING"
1488+
14791489
case $ac_sys_system in
14801490
SCO_SV*) OPT="$OPT -m486 -DSCO5"
14811491
;;

0 commit comments

Comments
 (0)