Skip including cpuid.h under Windows with Clang-cl#296
Skip including cpuid.h under Windows with Clang-cl#296ericstone93 wants to merge 3 commits intomicrosoft:mainfrom
Conversation
|
@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). |
|
The original issue was that |
|
Library still builds with clang-cl v12, so I'm going to go with this one. That said, there are some additional files in the repo that need updating for this change as well: |
|
There are also some new warnings here that need a cast: Both need to be: |
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__cpuidand__cpuidexintrinsics. 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_VERas 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.