I have an existing c++ project that compiles fine with msvc, and I'm trying to get it to compile in Visual Studio 2022 with LLVM (clang-cl). At the moment I'm using C++ Language Standard Preview ISO C++23, although I don't think this is necessary and would prefer C++20.
Visual Studio Installer tells me I have "C++ Clang Compiler for Windows (19.1.5)" and "MSBuild support for LLVM (clang-cl) toolset".
The project won't compile, it generates hundreds of compile errors. Some popular ones are:
E0020 identifier "__bf16" is undefined (in avx512bf16intrin.h, avxintrin.h and others)
E0020 the global scope has no "int8_t" (in cstdint, xutility, _msvc_minmax.hpp, and others)
E0020 identifier SETJTMP_FLOAT128 is undefined (in setjtmp.h)
What do I need to do to get over the hump? Surely the answer is simple, and duplicated on SO, but I've been Googling for 3 or 4 hours and evidently have not found the right key words for this issue.
Here's a small example that has most of the same compile errors. I was starting to suspect my issues had a lot to do with Agner's vcl, so I just threw his dispatcher sample code into a new project and hit the compile error jackpot. Note, compared to Agner's precise code I am doing some minor edits of the files instrset.h and instrset_detect.cpp to put clang over MSC. Agner's code has clang below MSC and works fine for compiling in standalone clang, but not in Visual Studio clang. Agner's original instrset.h and instrset_detect.cpp are retained in the vcl_agner subdirectory. If you use them you still get most of the same errors.
https://drive.google.com/file/d/1IElPqwWVvifvLHBj94JmjOptmH9tgIGw/view?usp=drive_link
Here is an example with silly-simple simd code. It will generate all the intellisense compile "errors", but it will compile and run correctly. My real code and the code linked above won't compile, but the fatal build errors are linker errors that don't happen compiling in msvc, only when compiling in clang. So I suppose I should be concentrating on the link errors.
#include <stdio.h>
#include <x86intrin.h>
//#include <immintrin.h>
//#define SIMD_SIZE_SPN 8
#define SIMD_SIZE_SPN 4
//#define SIMD_SIZE_SPN 2
int main() {
printf("\nhello ms clang\n");
double xarr[SIMD_SIZE_SPN] = {};
#if SIMD_SIZE_SPN == 8
__m512d vec1, vec2;
vec1 = _mm512_setr_pd(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0);
vec2 = _mm512_setr_pd(8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0);
vec1 = _mm512_mul_pd(vec1, vec2); //8, 14, 18, 20, 20, 18, 14, 8
_mm512_storeu_pd(xarr, vec1);
#elif SIMD_SIZE_SPN == 4
__m256d vec1, vec2;
vec1 = _mm256_setr_pd(1.0, 2.0, 3.0, 4.0);
vec2 = _mm256_setr_pd(4.0, 3.0, 2.0, 1.0);
vec1 = _mm256_mul_pd(vec1, vec2); //4, 6, 6, 4
_mm256_storeu_pd(xarr, vec1);
#else
__m128d vec1, vec2;
vec1 = _mm_setr_pd(1.0, 2.0);
vec2 = _mm_setr_pd(2.0, 1.0);
vec1 = _mm_mul_pd(vec1, vec2); //2, 2
_mm_storeu_pd(xarr, vec1);
#endif
printf("\nlast = %8.2f \n", xarr[SIMD_SIZE_SPN - 1]); //8, 4, 2
return 0;
}
[mre]?Eare not compiler errors, but comes from Intellisense. You can filter the results to show Build errors only, to get the compiler's take on the code.