Skip to content

Commit

Permalink
bpo-30104: Use -fno-strict-aliasing on clang (python#1221)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
vstinner authored Apr 21, 2017
1 parent 791dc83 commit 28205b2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
22 changes: 16 additions & 6 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -6814,8 +6814,15 @@ then

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

case $ac_cv_prog_cc_g in
Expand All @@ -6824,18 +6831,21 @@ then
# Optimization messes up debuggers, so turn it off for
# debug builds.
if "$CC" -v --help 2>/dev/null |grep -- -Og > /dev/null; then
OPT="-g -Og -Wall $STRICT_PROTO"
OPT="-g -Og -Wall"
else
OPT="-g -O0 -Wall $STRICT_PROTO"
OPT="-g -O0 -Wall"
fi
else
OPT="-g $WRAP -O3 -Wall $STRICT_PROTO"
OPT="-g $WRAP -O3 -Wall"
fi
;;
*)
OPT="-O3 -Wall $STRICT_PROTO"
OPT="-O3 -Wall"
;;
esac

OPT="$OPT $STRICT_PROTO $ALIASING"

case $ac_sys_system in
SCO_SV*) OPT="$OPT -m486 -DSCO5"
;;
Expand Down
22 changes: 16 additions & 6 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1454,8 +1454,15 @@ then

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

case $ac_cv_prog_cc_g in
Expand All @@ -1464,18 +1471,21 @@ then
# Optimization messes up debuggers, so turn it off for
# debug builds.
if "$CC" -v --help 2>/dev/null |grep -- -Og > /dev/null; then
OPT="-g -Og -Wall $STRICT_PROTO"
OPT="-g -Og -Wall"
else
OPT="-g -O0 -Wall $STRICT_PROTO"
OPT="-g -O0 -Wall"
fi
else
OPT="-g $WRAP -O3 -Wall $STRICT_PROTO"
OPT="-g $WRAP -O3 -Wall"
fi
;;
*)
OPT="-O3 -Wall $STRICT_PROTO"
OPT="-O3 -Wall"
;;
esac

OPT="$OPT $STRICT_PROTO $ALIASING"

case $ac_sys_system in
SCO_SV*) OPT="$OPT -m486 -DSCO5"
;;
Expand Down

0 comments on commit 28205b2

Please sign in to comment.