Fix Windows MSVC Debug build of XNNPACK and clang-cl kernel gating - #22163
Open
SS-JIA wants to merge 1 commit into
Open
Fix Windows MSVC Debug build of XNNPACK and clang-cl kernel gating#22163SS-JIA wants to merge 1 commit into
SS-JIA wants to merge 1 commit into
Conversation
Summary: Building any Debug preset with XNNPACK enabled under the MSVC toolset fails to compile backends/xnnpack/third-party/XNNPACK/src/subgraph.c. XNNPACK nests two variadic macros: XNN_RETURN_IF_ERROR expands to xnn_log_error, which in turn concatenates a location suffix onto its first parameter. MSVC's default legacy preprocessor forwards the outer __VA_ARGS__ into the inner macro as a single un-split argument, so the suffix is glued onto the last format argument rather than the format string, producing "syntax error: missing ')' before 'string'". Only the three call sites that pass a format string plus format arguments are affected. Release builds escape it because XNN_LOG_LEVEL is 0 outside of Debug, which makes xnn_log_error expand to nothing, and that is why the Release-only windows-msvc CI job never caught this. Enable /Zc:preprocessor for XNNPACK when the compiler is genuine MSVC. The same investigation turned up a second problem. The llm preset disables the quantized and LLM kernels on Windows whenever the MSVC variable is set, but CMake also sets MSVC for clang-cl, so those kernels were being dropped from clang-cl builds while the accompanying warning told the user to switch to -T ClangCL in order to get them. That contradicts the stated intent of #15719, so the check now keys off CMAKE_CXX_COMPILER_ID instead. Fixes #22084. Test Plan: On Windows with VS 2022 (MSVC 19.43), configured with the default MSVC toolset and built the xnnpack-subgraph target in Debug. Before the change the build fails with C2143/C2059 at subgraph.c lines 2663, 2918 and 3500, matching the issue report exactly; after the change it succeeds and produces xnnpack-subgraph.lib. Separately compiled all 96 XNNPACK logic-layer sources with XNN_LOG_LEVEL=5 both with and without /Zc:preprocessor to confirm the flag introduces no new diagnostics. Verified that cmake --preset llm-debug still disables the quantized and LLM kernels and warns under MSVC, and now enables them under -T ClangCL, where custom_ops, quantized_kernels and quantized_ops_lib all build clean. Reviewers: Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
SS-JIA
requested review from
digantdesai,
kirklandsign and
larryliu0820
as code owners
August 25, 2026 21:16
This PR needs a
|
digantdesai
approved these changes
Aug 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #22084.
The bug
Any Debug preset with XNNPACK enabled fails to compile
XNNPACK/src/subgraph.cunder the MSVC toolset:XNNPACK nests two variadic macros.
XNN_RETURN_IF_ERROR(src/xnnpack/internal.h) expands toxnn_log_error("" __VA_ARGS__), andxnn_log_error(src/xnnpack/log.h) is itself variadic and concatenates a location suffix onto its first parameter:MSVC's default legacy preprocessor forwards the outer
__VA_ARGS__into the inner macro as a single un-split argument.formattherefore binds to the whole blob and the suffix is glued onto the last argument instead of the format string, yieldingnode_id " (%s, %s:%i)". Only the three call sites insubgraph.cthat pass a format string plus format arguments are affected, which is exactly lines 2663, 2918 and 3500 at the currently pinned XNNPACK revision./Zc:preprocessorselects MSVC's conformant preprocessor and resolves it. The guard keys offCMAKE_C_COMPILER_IDrather than theMSVCvariable becauseMSVCis also true under clang-cl, which already conforms.Why CI is green today
XNN_LOG_LEVELis5only for$<CONFIG:Debug>and0otherwise, so in Releasexnn_log_errorexpands to nothing and the broken expansion never happens. The existingwindows-msvcjob builds Release only, leaving Debug uncovered. A cheap regression guard would be adding-DEXECUTORCH_XNNPACK_LOG_LEVEL=5to.ci/scripts/setup-windows-msvc.ps1, which exercises the path without a second full build; I left that out of this PR to keep it reviewable, happy to add it if wanted.Second, related fix
tools/cmake/preset/llm.cmakedisabled the quantized and LLM kernels on Windows whenever theMSVCvariable was set. CMake also setsMSVCfor clang-cl, so those kernels were silently dropped from every Windows clang-cl build while the accompanying warning advised the user to switch to-T ClangCLin order to get them. That contradicts the stated intent of #15719 ("Only block when building with MSVC"), so the check now usesCMAKE_CXX_COMPILER_ID. Thepybindpreset already enables the same kernels and is built with-T ClangCLin Windows CI, so this path is covered.Testing
On Windows with VS 2022 (MSVC 19.43):
xnnpack-subgraphin Debug under the default MSVC toolset fails with the errors above before the change and builds cleanly after it.XNN_LOG_LEVEL=5, with and without/Zc:preprocessor, confirming the flag introduces no new diagnostics.cmake --preset llm-debugstill disables the kernels and warns under MSVC, and now enables them under-T ClangCL, wherecustom_ops,quantized_kernelsandquantized_ops_liball build clean.cmake-formatandcmakelintpass on both files.Follow-up, not in this PR
make parakeet-vulkanbuilds the ExecuTorch core withllm-debug-vulkanbut the runner with a preset pinned toRelease. On MSVC that is a/MDdvs/MDCRT mismatch, so the reporter is likely to hitLNK2038next. Every other backend pairs like with like (parakeet-cudausesllm-release-cuda). The fix is presumably anllm-release-vulkanpreset mirroringllm-release-cuda, but that changes behaviour for existing Linux users of the target so it belongs on its own.This PR was authored with Claude Code.
🤖 Generated with Claude Code