microsoft / DirectXMath

DirectXMath is an all inline SIMD C++ linear algebra library for use in games and graphics apps
https://walbourn.github.io/introducing-directxmath/
MIT License
1.51k stars 231 forks source link

__cpuid and clang-cl #156

Closed matbech closed 1 year ago

matbech commented 1 year ago

With clang-cl (15.0.4) using Clang Power Tools, I'm getting the following compiler error in XMVerifyCPUSupport:

C:\Program Files (x86)\Windows Kits\10\Include\10.0.25276.0\um/DirectXMathMisc.inl:1977:5: error: no matching function for call to '__cpuid'
    __cpuid(0, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]);
    ^~~~~~~
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.35.32019\include\intrin.h(191): message: candidate function not viable: requires 2 arguments, but 5 were provided
__MACHINEX86_X64(void __cpuid(int[4], int))

The problem is that with clang-cl, both __clang__ and _MSC_VER are defined. And in this case intrin.h is included in DirectXMath.h (https://github.com/microsoft/DirectXMath/blob/main/Inc/DirectXMath.h#L117) and __cpuid from this header should be used.

walbourn commented 1 year ago

I see the problem now... You should not be using intrin.h from the MSVC toolset when building with clang-cl. You should be using the intrin.h that comes with your clang/LLVM.

While you can get it to "build" with the intrin.h from MSVC, it doesn't actually work at runtime and thus crashes.

walbourn commented 1 year ago

Note that I specifically test clang/LLVM for Window as integrated into Visual Studio. I'm not sure what exactly Clang Power Tools is setting up.

matbech commented 1 year ago

Thank you for pointing this out. I will report the issue to Clang Power Tools.