This is an archive of the discontinued LLVM Phabricator instance.

[clang][Driver] Expose driver mode detection logic
ClosedPublic

Authored by kadircet on Jul 26 2021, 5:10 AM.

Details

Summary

Also use it in other places that performed it on their own.

Diff Detail

Event Timeline

kadircet requested review of this revision.Jul 26 2021, 5:10 AM
kadircet created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJul 26 2021, 5:11 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
kadircet updated this revision to Diff 361646.Jul 26 2021, 7:24 AM
  • Preserve no diagnostic behaviour in case of an empty driver.
sammccall accepted this revision.Jul 27 2021, 5:12 AM
sammccall added inline comments.
clang/include/clang/Driver/Driver.h
643

List the "good" values, and explicitly mention that it need not be one?

clang/lib/Driver/Driver.cpp
1016–1019

can we do this only if we have a value to set to, and remove the "" special case?

clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
149

could consider adding isClangCL(StringRef)... up to you

This revision is now accepted and ready to land.Jul 27 2021, 5:12 AM
This revision was landed with ongoing or failed builds.Jul 27 2021, 5:55 AM
This revision was automatically updated to reflect the committed changes.
kadircet marked 3 inline comments as done.
hans added a subscriber: hans.Sep 7 2021, 4:41 AM

Somehow this seems to have broken the --driver-mode= flag when passed to clang-cl. The flag is supposed to override the mode inferred from the filename, but it's not working anymore. For example:

Before:

$ bin/clang-cl --driver-mode=gcc -target x86_64 -c /tmp/a.c -###
clang version 13.0.0 (https://github.com/llvm/llvm-project 7dc9d7373186827a92d6ca08ad7192208dfea389)
[...]

After:

$ bin/clang-cl --driver-mode=gcc -target x86_64 -c /tmp/a.c -###
clang-13: warning: unknown argument ignored in clang-cl: '-target' [-Wunknown-argument]
clang version 13.0.0 (https://github.com/llvm/llvm-project ce90b60bd09da41c52006374a4715425122572ab)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: /work/llvm.monorepo/build.release/bin
clang-13: error: no such file or directory: 'x86_64'
[...]

Can you take a look?

Argh, sorry for the mess, sent out D109361.

FYI, before this patch clang preferred the last --driver-mode in case of multiple ones and started preferring the first one with this patch. In https://github.com/llvm/llvm-project/blob/main/clang/tools/driver/driver.cpp#L474 it always inserts a --driver-mode matching the program name at the beginning of the command line, hence it was always preferring CL mode even though you explicitly mentioned GCC afterwards.