This is an archive of the discontinued LLVM Phabricator instance.

[asan][test][win] Port more tests to not use clang-cl on MinGW
ClosedPublic

Authored by alvinhochun on Apr 3 2023, 8:03 AM.

Diff Detail

Event Timeline

alvinhochun created this revision.Apr 3 2023, 8:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 3 2023, 8:03 AM
Herald added a subscriber: Enna1. · View Herald Transcript
alvinhochun requested review of this revision.Apr 3 2023, 8:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 3 2023, 8:03 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript

Fix mistake

vitalybuka requested changes to this revision.Apr 3 2023, 1:37 PM
vitalybuka added inline comments.
compiler-rt/test/asan/TestCases/Windows/crt_initializers.cpp
1–2

I believe it would be much cleaner if done substituting: llvm-project/compiler-rt/test/asan/lit.cfg.py:163

This revision now requires changes to proceed.Apr 3 2023, 1:37 PM
alvinhochun added inline comments.Apr 4 2023, 7:30 AM
compiler-rt/test/asan/TestCases/Windows/crt_initializers.cpp
1–2

I don't know how one could use substitution for this, since clang and clang-cl use very different command line parameters (especially problematic for the more complex DLL tests which I have yet to port).

Or do you mean using substitution to turn certain RUN: commands into comments? Like:

// RUN: %if_clang_cl %clang_cl_asan -Od %s -Fe%t
// RUN: %if_not_clang_cl %clangxx_asan -O0 %s -o %t

...and conditionally substituting one of %if_clang_cl and %if_not_clang_cl to be : and the other one to be empty?

mstorsjo added inline comments.Apr 4 2023, 11:20 AM
compiler-rt/test/asan/TestCases/Windows/crt_initializers.cpp
1–2

You could make one substitution for -Fe or -o (note, including the trailing space), another one for -O0 vs -Od etc.

Sorry if it’s obvious if I haven’t followed closely enough, but would it be possible to port the tests to use the gcc driver syntax even with clang in msvc mode? (I understand that that would be a bigger undertaking though.) Or are these tests executed with cl.exe too, so we need to remain compatible with that syntax anyway?

alvinhochun added inline comments.Apr 5 2023, 2:24 AM
compiler-rt/test/asan/TestCases/Windows/crt_initializers.cpp
1–2

If we need one substitution per flag, I don't know how many substitutions we will end up having, and I may have difficulty naming them. Some flags may also be incompatible (mingw needs -Wl,--out-implib to generate import lib). To me it feels messier than just writing the commands separately.

Rewriting to use gcc driver syntax shouldn't be hard, but I am afraid of breaking them due to obscure differences between the two drivers (things like static/dynamic, debug/release crt). I suppose these tests also serve the purpose of testing asan support in the clang-cl driver so perhaps they should continue to use clang-cl.

It doesn't look like the tests would work with cl.exe out of the box though.

mstorsjo added inline comments.Apr 10 2023, 2:41 PM
compiler-rt/test/asan/TestCases/Windows/crt_initializers.cpp
1–2

@vitalybuka - Can you elaborate on how you want this to be substituted?

vitalybuka added inline comments.Apr 11 2023, 6:23 PM
compiler-rt/test/asan/TestCases/Windows/crt_initializers.cpp
1–2

Per flag, like %fPIC llvm-project/compiler-rt/test/asan/lit.cfg.py:234 ?

vitalybuka added inline comments.Apr 11 2023, 6:26 PM
compiler-rt/test/asan/TestCases/Windows/crt_initializers.cpp
1–2

at least for frequent stuff
for flags which are in 1-2 tests if/else should be fine

vitalybuka added inline comments.
compiler-rt/test/asan/TestCases/Windows/crt_initializers.cpp
1–2

@phosek @MaskRay Do you have opinion on %if %else in run lines?
Maybe I am unfairly biased against them, when they are reasonable way to solve the problem?

Use substitution to map clang-cl command and flags to clang gcc-style flags on MinGW

MaskRay added inline comments.Apr 13 2023, 1:36 PM
compiler-rt/test/asan/TestCases/Windows/crt_initializers.cpp
1–2

I'll certainly avoid complex constructs if possible.
When they provide values, I'll not simply keep them off.

rg '%if target=' compiler-rt/test/ has some examples.

Bonus: our internal lit runner supports many %if constructs.

mstorsjo added inline comments.Apr 13 2023, 1:51 PM
compiler-rt/test/asan/TestCases/Windows/crt_initializers.cpp
1–2

@MaskRay Yes, all those hits in compiler-rt/test are ones added by @alvinhochun recently. The question is mostly here whether we should prefer adding more %if conditions in the test (older revision of this patch) or add more substitutions, to make parametrized expansions that work across both clang-cl and mingw.

As an example - D147432 (which this patch depends on) changes RUN lines with %clang_cl_asan -Od %s -Fe%t into %clang_cl_asan %Od %s %Fe%t, and for mingw mode, %Od expands to -O0 and %Fe expands to -o. The run lines get a bit more cryptic, but it works. (But for more complex tests it might not be enough with just such substitutions, but actual conditionals might be needed.)

vitalybuka accepted this revision.Apr 19 2023, 4:05 PM
This revision is now accepted and ready to land.Apr 19 2023, 4:05 PM