Skip to content

Commit b2ab44b

Browse files
authored
Fix "access violation" failures that have appeared in new windows builds by disabling compiler optimization on windows (#1077)
The root cause was a compiler autovectorization bug. Turning off optimizations will hurt performance but at least make the code not *totally broken*. Reproduction of the bug in a simpler instance: ``` #include <cstdint> #include <iostream> uint64_t repro() { uint32_t targets[6]{0, 27, 0, 0, 27, 0}; uint64_t t = 6; for (size_t k = 0; k < 6; k++) { if (targets[k] == 27) { t -= 2; } } return t; } int main() { std::cerr << "t=" << repro() << "\n"; return 0; } ``` Go to godbolt, paste the above code, compile it with the compiler `x64 msvc v19.51 VS18.6` and flags `/O2` and run it and it will print `t=8589934594` instead of `t=2`. Fixes #1078
1 parent 56769dd commit b2ab44b

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
[build-system]
22
requires = ["setuptools", "wheel", "pybind11~=2.11.1"]
33
build-backend = "setuptools.build_meta"
4+
5+
[tool.cibuildwheel.windows.environment]
6+
# CAUTION! This is /Od instead of /O2 because of bugs in the msvc compiler!
7+
# See: https://github.com/quantumlib/Stim/issues/1078
8+
CFLAGS = "/Od"
9+
CXXFLAGS = "/Od"

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
if platform.system().startswith('Win'):
3131
common_compile_args = [
3232
'/std:c++20',
33-
'/O2',
33+
# CAUTION! This is /Od instead of /O2 because of bugs in the msvc compiler!
34+
# See: https://github.com/quantumlib/Stim/issues/1078
35+
'/Od',
3436
f'/DVERSION_INFO={__version__}',
3537
]
3638
arch_avx = ['/arch:AVX2']

0 commit comments

Comments
 (0)