Skip to content

Remove MSVC __assume from GECODE_ASSUME and fix Windows ARM64 build - #305

Open
zayenz wants to merge 1 commit into
mainfrom
fix/msvc-assume
Open

zayenz wants to merge 1 commit into
mainfrom
fix/msvc-assume

Conversation

@zayenz

@zayenz zayenz commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Release builds of Gecode compiled with Visual Studio 2026 (MSVC 19.52) lose solutions on basic integer constraints on both ARM64 and x64. The MiniZinc FindMUS team reported the failure on Gecode 6.6.1 built for Windows ARM64 (minizinc-vendor), where a satisfiable 3x3 FlatZinc model (all_different on one column and two lex_less constraints) returned UNSATISFIABLE.

The root cause is an MSVC 19.52 optimizer bug triggered by __assume in GECODE_ASSUME. Removing __assume fixes the miscompilation, passing /bigobj fixes the MSVC ARM64 build, and a new Windows ARM64 release-matrix job tests both.

Cause

The FindMUS reproducer uses the C++ API to count solutions against brute force for rel(home, x, irt, y) on IntVarArgs across all relations and lengths 1..4 over domains 1..3, plus distinct and the 3x3 model. On Linux x64 all 26 cases match brute force. On Windows ARM64 Release, 21 of 26 cases fail: every case except != and distinct loses solutions. Length-1 comparisons fail too (x < y yields 0 of 3 solutions, x == y yields 1 of 3). Because length-1 lex posts the binary Le/Lq propagators and lex == posts EqDom, the bug was not in the lex propagator.

To isolate it, Gecode 6.6.1 was built in Release with MSVC 19.52.37029 (Visual Studio 2026) on GitHub Actions (zayenz/gecode, branch debug/win-arm-lex) on both windows-11-arm (ARM64) and windows-2025 (x64, which also ships MSVC 19.52), with and without __assume:

  • With GECODE_ASSUME(p) defined as __assume((p)) (the default under _MSC_VER && NDEBUG), both ARM64 and x64 fail the same 21 of 26 reproducer cases, and gecode-test fails immediately on Int::Distinct::Bnd::Dense.
  • With GECODE_ASSUME defined empty, all 26 cases pass on both architectures, and the Int::Rel and Int::Distinct test suites pass.

The trigger is MSVC 19.52, not ARM64. It looked ARM64-specific only because Gecode's CI and MiniZinc's x64 Windows package still build on windows-2022 (Visual Studio 2022), whereas windows-11-arm ships Visual Studio 2026.

The asserted conditions hold: on all other compilers GECODE_ASSUME is a normal assert, and per-PR CI checks them in Debug builds (check-extended). GECODE_ASSUME is used in IntVarImp bound updates (lq/gq/eq, asserting the result is FAILED, VAL, or BND), float variable updates, kernel core, thread.cpp, and a few graph, extensional, and tuple-set paths. A small standalone copy of the IntVarImp pattern did not reproduce the miscompile, so there is no minimal bug report for Microsoft yet.

Changes

  • gecode/support/macros.hpp: define GECODE_ASSUME(p) as assert((p)) on all compilers instead of expanding to __assume((p)) in MSVC Release builds. Other compilers never had an optimizer hint there.
  • CMakeLists.txt: pass /bigobj to MSVC C++ compiles. Without it, gecode/int/extensional-tuple-set.cpp fails on ARM64 with C1128 (too many sections), which minizinc-vendor worked around via CXXFLAGS. (The removed Autoconf build always passed -bigobj; main is CMake-only.)
  • .github/workflows/release-matrix.yml: add build-windows-arm64 on windows-11-arm using the runner's default (newest) Visual Studio, static Release configuration, running the check target. That job would have caught both problems.
  • changelog.in: add two entries in the unreleased 7.0.0 section.

Testing

The release-matrix workflow runs on workflow_dispatch, pushes to release/**, and pull requests that touch .github/workflows/release-matrix.yml. Because the workflow file changes here, build-windows-arm64 runs automatically on the pull request: it builds a static Release configuration on windows-11-arm with Visual Studio 2026 and runs check.

Follow-up

This fix should be backported for a 6.6.2 release together with the FlatZinc blackbox improvements and PR #302. On 6.6.x, the bundled Boost.Interval header hw_rounding.hpp also needs to recognize _MSVC_LANG so ARM64 MSVC builds do not require /Zc:__cplusplus; main no longer has that code.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed incorrect or missing solutions for integer-constraint problems in Release builds with recent MSVC versions on x64 and ARM64.
    • Fixed Windows ARM64 compilation failures caused by large object files. MSVC builds now use compiler settings that support them.

Release builds made with Visual Studio 2026 (MSVC 19.52.37029) lose
solutions on basic integer constraints. On a 26-case reproducer from
MiniZinc's FindMUS team, 21 cases return too few solutions, including
length-1 comparisons such as x < y (0 of 3) and x == y (1 of 3) and a
satisfiable 3x3 model that reports UNSATISFIABLE. gecode-test fails
immediately on Int::Distinct::Bnd::Dense.

Rebuilding Gecode 6.6.1 on GitHub Actions with MSVC 19.52 reproduces
the same 21 failures on both windows-11-arm (ARM64) and windows-2025
(x64) when GECODE_ASSUME expands to __assume. Defining GECODE_ASSUME
empty makes all 26 cases and the Int::Rel and Int::Distinct tests pass
on both architectures. The asserted properties hold and are checked in
Debug builds in per-PR CI, so this is an MSVC 19.52 optimizer bug
triggered by __assume. It was only noticed on ARM64 because Gecode CI
and MiniZinc's x64 package still build with Visual Studio 2022.

Define GECODE_ASSUME(p) as assert((p)) on all compilers in
gecode/support/macros.hpp; non-MSVC compilers never used an optimizer
hint there. Pass /bigobj to MSVC C++ compiles in CMakeLists.txt so
gecode/int/extensional-tuple-set.cpp builds on ARM64 without hitting
C1128 (too many sections). Add a build-windows-arm64 job to
.github/workflows/release-matrix.yml on windows-11-arm using the
runner's default Visual Studio in a static Release build that runs the
check target. That job would have caught both problems.
@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: MSVC assumption handling

Layer / File(s) Summary
Use assert for GECODE_ASSUME
gecode/support/macros.hpp, changelog.in
GECODE_ASSUME now expands to assert((p)) in all configurations. The changelog records incorrect Release-build results with MSVC 19.52 on x64 and ARM64.

Windows ARM64 build support

Layer / File(s) Summary
Configure and validate Windows ARM64 builds
CMakeLists.txt, .github/workflows/release-matrix.yml, changelog.in
CMake adds /bigobj for MSVC C++ compilation. The release matrix adds a Windows ARM64 job that builds and runs check. The changelog records the C1128 build issue.

Possibly related PRs

  • Gecode/gecode#297: Creates the release-matrix workflow that this PR extends with a Windows ARM64 job.

Suggested reviewers: chschulte

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · up to 614c3

This change removes an optimizer assumption that caused lost solutions with Visual Studio 2026 Release builds. It also fixes the Windows ARM64 build and adds a CI check for it. No merge-blocking risk is evident.

Architecture risk: Low · up to 614c3

GECODE_ASSUME no longer gives MSVC Release builds optimizer assumptions, while the build adds /bigobj and Windows ARM64 CI validation.

When callers pass predicates to GECODE_ASSUME, the macro now uses assert rather than supplying optimizer assumptions; with NDEBUG, those predicates are not evaluated.

Changed areas: changelog.in, CMakeLists.txt, gecode

Review details

Systems and components

  • observed — 1 changed file mapped to changelog.in.
  • observed — 1 changed file mapped to CMakeLists.txt.
  • observed — 1 changed file mapped to gecode.
Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 4e5813df-9849-4f3d-900e-571ff7f9375a
Commits

Reviewing files that changed from the base of the PR and between f6a34ca and 614c328.

Files selected for processing: 4

  • .github/workflows/release-matrix.yml
  • CMakeLists.txt
  • changelog.in
  • gecode/support/macros.hpp

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant