Skip to content

Use a portable popcount so MSVC can build the LLVM backend - #31

Merged
siahisaforker merged 1 commit into
ExpansionPak:mainfrom
dougchansan:fix/msvc-popcount
Sep 17, 2026
Merged

siahisaforker merged 1 commit into
ExpansionPak:mainfrom
dougchansan:fix/msvc-popcount

Conversation

@dougchansan

Copy link
Copy Markdown
Contributor

__builtin_popcountll is a GCC/Clang builtin with no MSVC equivalent, so an MSVC build of the LLVM backend fails outright on main:

abi_policy.cpp(15): error C3861: '__builtin_popcountll': identifier not found

Why CI does not catch it

No job builds that combination:

job LLVM backend compiler
build (windows-latest, Release, cl, cl) off — so src/backend/llvm/abi_policy.cpp is never compiled MSVC
LLVM backend (windows-latest) on MSYS2/UCRT64 mingw GCC, which has the builtin

MSVC plus the LLVM backend is the configuration a local Windows toolchain actually uses (vcvars64 + an LLVM release build), and it is the one combination CI never exercises.

The change

std::bitset<64>::count() is C++17, needs no feature test or #ifdef, and lowers to popcnt on every compiler that has the instruction. This was the only __builtin_ in src/.

Verification

Built and tested on three hosts, all with -DDOLRECOMP_ENABLE_LLVM=ON:

host toolchain before after
Windows MSVC 14.50 + LLVM 20.1.8 build fails build clean, 32/32 tests pass
Linux GCC + LLVM 20.1.2 33/33 pass 33/33 pass
macOS arm64 Apple clang + LLVM 20.1.8 3 tests fail 3 tests fail (identical set)

The three macOS failures (modern_codegen, llvm_codegen, llvm_pipeline) are pre-existing and unrelated to this change — I confirmed by reverting only this hunk on the same tree and re-running serially, which produced the identical failure set. They are also not what blocks the macOS build; that is the Mach-O section specifier issue fixed by #26.

Note for anyone reproducing the macOS numbers: run ctest -j1. Under -j10 those tests contend over shared artifacts in the build directory and report an inconsistent subset of failures between runs.

Suggested follow-up

Adding -DDOLRECOMP_ENABLE_LLVM=ON to the MSVC CI job would close the gap that let this land.

__builtin_popcountll is a GCC/Clang builtin with no MSVC equivalent, so
an MSVC build of the LLVM backend fails outright:

  abi_policy.cpp(15): error C3861: '__builtin_popcountll': identifier not found

CI does not catch this because no job builds that combination. The
windows-latest MSVC job configures without DOLRECOMP_ENABLE_LLVM, so
this file is never compiled; the "LLVM backend (windows-latest)" job
does enable it but builds under MSYS2/UCRT64 with mingw GCC, which has
the builtin. MSVC plus the LLVM backend is the configuration a local
Windows toolchain actually uses.

std::bitset<64>::count() is C++17, needs no feature test, and lowers to
popcnt on every compiler that has the instruction. This was the only
__builtin_ in src/.
@siahisaforker
siahisaforker merged commit 46a29b8 into ExpansionPak:main Sep 17, 2026
6 checks passed
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.

2 participants