Skip to content

Skip including cpuid.h under Windows with Clang-cl#296

Open
ericstone93 wants to merge 2 commits intomicrosoft:mainfrom
ericstone93:user/ruishi/Clang-FixWindowsDirectXMathInclude
Open

Skip including cpuid.h under Windows with Clang-cl#296
ericstone93 wants to merge 2 commits intomicrosoft:mainfrom
ericstone93:user/ruishi/Clang-FixWindowsDirectXMathInclude

Conversation

@ericstone93
Copy link
Copy Markdown

@ericstone93 ericstone93 commented Apr 29, 2026

Summary

The issue is it includes <cpuid.h> when __clang__ is defined and __x86_64__ is set, but NOT on MinGW. This is the standard DirectXMath header from the Windows SDK.

On Linux/Mac with Clang, <cpuid.h> is a Clang/GCC built-in header that provides __cpuid and __cpuidex intrinsics. But on Windows with Clang-cl, those intrinsics come from <intrin.h> instead (which is already included on line 118 for _MSC_VER).

Since Clang-cl defines both __clang__ AND _MSC_VER, it hits both the <intrin.h> include (good) AND the <cpuid.h> include (bad, doesn't exist on Windows). The fix is to exclude _MSC_VER as in the PR.

Change

Add !defined(_MSC_VER) to the <cpuid.h> include condition so it only applies to non-MSVC-compatible Clang/GCC on Linux/Mac x86 targets.

@ericstone93 ericstone93 marked this pull request as ready for review April 29, 2026 23:52
@ericstone93 ericstone93 changed the title Clang - Skip including cpuid.h under Windows Skip including cpuid.h under Windows with Clang-cl Apr 29, 2026
@walbourn walbourn self-assigned this Apr 30, 2026
@walbourn walbourn added the conformance Related to supporting non-MSVC compilers label Apr 30, 2026
@walbourn walbourn requested a review from Andrew-Farrier April 30, 2026 03:05
@walbourn
Copy link
Copy Markdown
Member

@Andrew-Farrier I recall we specifically used cpuid.h instead of intrin.h for DirectXMath 3.14. IIRC, the intrin.h approach resulted in bad codegen on clang for Windows.

Do you remember the bug? Any way we can verify if it's fixed in newer clang compilers (the issue dates back to the Windows SDK (19041) timeframe).

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

Labels

conformance Related to supporting non-MSVC compilers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants