Open davidben opened 3 months ago
Could you please try 18 or main
branch?
We declare other non-static intrinsics as extern "C": https://github.com/llvm/llvm-project/blob/main/clang/lib/Headers/intrin.h#L48
Although these are really a bunch of fake declarations.
New versions of clang might not have the issue due to the new intrin0.h change.
Hi, original reporter here. I tested that this issue still presents in Clang 18.1.2, and is fixed in main
.
May I ask if I can expect this fix to be landed on a future 18.x release, or I should wait until 19?
Can confirm the new 18.1.4 does not fix this. I am struggling to compile the main branch, but for now I've wrapped _m_prefetchw in an extern C
. Interestingly I'm running into this and some other issues with llvm when I'm trying to recompile tensorflow for my machine (to improve AVX support as it reports there's performance left on the table) on Windows. Tensorflow says 17.0.6 worked. Visual Studio has 17.0.3 in its installer. I may give those a try if this hack doesn't work.
It's interesting you mention the problem is fixed on main because I didn't see any changes to the file that I thought would help. Maybe it's something higher up the include path that I'm not seeing. Did you compile main and have success with this?
Did you compile main and have success with this?
Yes. I also hit some weird error when using MSVC, but using Clang provided by Visual Studio I successfully compiled main branch quite smoothly.
We got a report in BoringSSL of a conflict between some Windows headers and clang-cl: https://bugs.chromium.org/p/boringssl/issues/detail?id=717
In short, if you build the following with MSVC's STL, clang-cl, and C++20...
The following error comes up:
(This is MSVC's clang-cl, but the reporter also can repro on Clang 18.)
The significance of C++20 mode seems to be that, in older C++ versions,
<windows.h>
does not pull in the Windows copy of the intrinsic. I have not determined why yet. The underlying conflict is language-independent, which is what Windows declares_m_prefetchw
as:Whereas Clang declares it this way, with no
extern
block:BoringSSL needs to wrap the C++ bits in its headers in
extern "C++"
to undo other projects including our headers insideextern "C"
blocks, which was too common to clear out. (People don't expect<openssl/foo.h>
to include C++ code.) C++ headers (such as the MSVC STL!) do not react well to being included underextern "C"
. So we have to useextern "C++"
to restore the default language linkage. However, it seems that restoring the default language linkage explicitly is not quite the same as leaving it undecorated:https://godbolt.org/z/8r8Mzhbvr https://godbolt.org/z/aKoGzMof1
Bizarrely, even the static mismatch seems it would be fatal, yet it isn't here. Does clang-cl special-case this somehow? https://godbolt.org/z/T84eq1j6q
I'm not sure what the right fix is, but given clang-cl is meant to coexist with Windows headers, I suspect the fix should be on the Clang side, one way or another. I'm not sure whether that means to give its intrinsics C linkage, add more quirks to this mismatch allowance, defer defining the intrinsics to Windows headers, or something else altogether.