diff options
author | Matti Picus <matti.picus@gmail.com> | 2019-09-14 20:12:29 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-14 20:12:29 +0300 |
commit | 31ffdecf07d18ed4dbb66b171cb0f998d4b190fa (patch) | |
tree | 027c82afa6841bf75704df22966df24d46c98258 /numpy/core/setup_common.py | |
parent | 79cb45d9c50875c61f3032f9047f02551661efa1 (diff) | |
parent | 6cf6ece43589670a28b765fd03402cc08ada61f0 (diff) | |
download | numpy-31ffdecf07d18ed4dbb66b171cb0f998d4b190fa.tar.gz |
Merge pull request #13739 from eric-wieser/bit_shifts
BUG: Don't produce undefined behavior for a << b if b >= bitsof(a)
Diffstat (limited to 'numpy/core/setup_common.py')
-rw-r--r-- | numpy/core/setup_common.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/numpy/core/setup_common.py b/numpy/core/setup_common.py index a3f7acd6d..84b78b585 100644 --- a/numpy/core/setup_common.py +++ b/numpy/core/setup_common.py @@ -5,6 +5,7 @@ import sys import warnings import copy import binascii +import textwrap from numpy.distutils.misc_util import mingw32 @@ -415,3 +416,41 @@ def long_double_representation(lines): else: # We never detected the after_sequence raise ValueError("Could not lock sequences (%s)" % saw) + + +def check_for_right_shift_internal_compiler_error(cmd): + """ + On our arm CI, this fails with an internal compilation error + + The failure looks like the following, and can be reproduced on ARM64 GCC 5.4: + + <source>: In function 'right_shift': + <source>:4:20: internal compiler error: in expand_shift_1, at expmed.c:2349 + ip1[i] = ip1[i] >> in2; + ^ + Please submit a full bug report, + with preprocessed source if appropriate. + See <http://gcc.gnu.org/bugs.html> for instructions. + Compiler returned: 1 + + This function returns True if this compiler bug is present, and we need to + turn off optimization for the function + """ + cmd._check_compiler() + has_optimize = cmd.try_compile(textwrap.dedent("""\ + __attribute__((optimize("O3"))) void right_shift() {} + """), None, None) + if not has_optimize: + return False + + no_err = cmd.try_compile(textwrap.dedent("""\ + typedef long the_type; /* fails also for unsigned and long long */ + __attribute__((optimize("O3"))) void right_shift(the_type in2, the_type *ip1, int n) { + for (int i = 0; i < n; i++) { + if (in2 < (the_type)sizeof(the_type) * 8) { + ip1[i] = ip1[i] >> in2; + } + } + } + """), None, None) + return not no_err |