On Fri Nov 25 16:57:37 2022 +0000, Martin Storsjö wrote:
The other problem is that clang for some reason doesn't define
`_MSC_VER` by default. I found that it's defined only if I pass `-fuse-ld=lld` to the command line. That's weird because it shouldn't affect compilation step, it should matter only for linking and that's when we pass it. I didn't track it down in clang code itself, but if we can't depend on clang providing it by default, we need to make sure to pass `-fms-compatibility-version` ourselves. The exact version doesn't really matter, we mostly need to make sure that it's defined at all so that our #ifdefs work correctly. This sounds extremely surprising - and I really don't see how `-fuse-ld=lld` could affect this. `_MSC_VER` is pretty much the most basic define for the MSVC target mode... Although I guess that if there's some heuristic for figuring out _what_ to set the define to, that can fail in some cases - maybe? The fix, setting `-fms-compatibility-version=19` is probably quite harmless in any case, but I'd be very much interested in figuring out what really is going on here. How do I reproduce this situation?
I tested it with:
``` $ echo _MSC_VER | clang -E -target x86_64-windows -fuse-ld=bfd - # 1 "<stdin>" # 1 "<built-in>" 1 # 1 "<built-in>" 3 # 341 "<built-in>" 3 # 1 "<command line>" 1 # 1 "<built-in>" 2 # 1 "<stdin>" 2 _MSC_VER
$ echo _MSC_VER | clang -E -target x86_64-windows -fuse-ld=lld - # 1 "<stdin>" # 1 "<built-in>" 1 # 1 "<built-in>" 3 # 355 "<built-in>" 3 # 1 "<command line>" 1 # 1 "<built-in>" 2 # 1 "<stdin>" 2 1920 ```
Trying a few more cases, it seems that the problem happens when `-fuse-ld` is bfd*, any other (possibly invalid) values work fine.