This is an archive of the discontinued LLVM Phabricator instance.

[clang] [test] Narrow down MSVC specific behaviours from "any windows" to only MSVC/clang-cl
ClosedPublic

Authored by mstorsjo on May 5 2023, 2:43 PM.

Diff Detail

Event Timeline

mstorsjo created this revision.May 5 2023, 2:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 5 2023, 2:43 PM
mstorsjo requested review of this revision.May 5 2023, 2:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 5 2023, 2:43 PM
hans accepted this revision.May 8 2023, 7:38 AM

lgtm

This revision is now accepted and ready to land.May 8 2023, 7:38 AM
This revision was landed with ongoing or failed builds.May 9 2023, 3:08 PM
This revision was automatically updated to reflect the committed changes.
thakis added a subscriber: thakis.May 10 2023, 4:50 AM

This broke check-clang on windows: http://45.33.8.238/win/78359/step_7.txt

(The Driver/split-debug.c failure is something else and since fixed, but the other two tests are due to this change.)

Please take a look and revert for now if it takes a while to fix.

This broke check-clang on windows: http://45.33.8.238/win/78359/step_7.txt

(The Driver/split-debug.c failure is something else and since fixed, but the other two tests are due to this change.)

Please take a look and revert for now if it takes a while to fix.

Sorry about this, and thanks for reverting. I’ll have a closer look at the issue later.

mstorsjo reopened this revision.May 10 2023, 9:52 AM
This revision is now accepted and ready to land.May 10 2023, 9:52 AM
mstorsjo added a subscriber: rnk.May 12 2023, 6:11 AM

So, the reason why this failed, is that when invoked as %clang_cc1 in a MSVC/clang-cl style build, _MSC_VER isn't predefined, while _WIN32 is. When invoked via the Clang driver instead of directly going at -cc1, _MSC_VER does get defined.

@rnk @hans @thakis - who know the intricacies of the MSVC target - do you happen to know why that is? How do I distinguish between MSVC-style behaviour and other cases (in particular, mingw) in a %clang_cc1 test? Currently it uses #idef _WIN32 but that's incorrect for mingw.

rnk added a comment.May 12 2023, 10:21 AM

So, the reason why this failed, is that when invoked as %clang_cc1 in a MSVC/clang-cl style build, _MSC_VER isn't predefined, while _WIN32 is. When invoked via the Clang driver instead of directly going at -cc1, _MSC_VER does get defined.

@rnk @hans @thakis - who know the intricacies of the MSVC target - do you happen to know why that is? How do I distinguish between MSVC-style behaviour and other cases (in particular, mingw) in a %clang_cc1 test? Currently it uses #idef _WIN32 but that's incorrect for mingw.

I think _MSC_EXTENSIONS will work, but it's kind of gross. _MSC_VER is controlled by -fms-compatibility-verson=, which I think is off by default or unset at the cc1 level:
https://github.com/llvm/llvm-project/blob/main/clang/lib/Basic/Targets/OSTargets.cpp#L206
-fms-extensions is on by default at cc1, I think.

This isn't great. It would be nice to have some kind of feature test mechanism for "which C++ ABI am I using, Itanium, one of the variants, or Microsoft".

I think _MSC_EXTENSIONS will work, but it's kind of gross. _MSC_VER is controlled by -fms-compatibility-verson=, which I think is off by default or unset at the cc1 level:
https://github.com/llvm/llvm-project/blob/main/clang/lib/Basic/Targets/OSTargets.cpp#L206
-fms-extensions is on by default at cc1, I think.

Ah, I see, thanks!

Since _MSC_VER is the most canonical way of checking for an MSVC-like environment anyway, do you think it'd make sense to define it to a dummy value like 1, if the target is an MSVC triple but no -fms-compatibility-version= is provided?

Using _MSC_EXTENSIONS instead of _MSC_VER in these tests isn't very pretty, but I guess it could be passable still? (I'm not setting out to improve all the world here right now, I'm just trying to get the tests passing in a mingw environment.)

mstorsjo updated this revision to Diff 521781.May 12 2023, 1:40 PM

Updated to check for defined(_WIN32) && !defined(__MINGW32__). It's a kinda ugly way of checking for an MSVC-like environment specifically (when the MSVC mode is the exception compared with the rest), but neither _MSC_VER or _MSC_EXTENSIONS are defined by default in a clang -cc1 invocation.

aaron.ballman accepted this revision.May 15 2023, 4:42 AM

Updated to check for defined(_WIN32) && !defined(__MINGW32__). It's a kinda ugly way of checking for an MSVC-like environment specifically (when the MSVC mode is the exception compared with the rest), but neither _MSC_VER or _MSC_EXTENSIONS are defined by default in a clang -cc1 invocation.

This seems like forward progress to me, so LG!