This is an archive of the discontinued LLVM Phabricator instance.

[llvm-driver] Fix clang -fno-integrated-cc1 when invoked from the llvm driver
AbandonedPublic

Authored by abrachet on Oct 3 2022, 2:58 PM.

Details

Reviewers
phosek
beanz
NoQ
Summary

Clang discovers the path to it's own executable and uses this
to re-invoke itself when -fno-integrated-cc1 is set, or if there are
multiple jobs, i.e. multiple source files specified. When clang is
invoked as part of the llvm driver, it's executable is going to be the
driver executable 'llvm', not the symlink 'clang', so the invocation
will look like 'llvm -cc1 ...'. The llvm driver will try to find an tool
called '-cc1' and will fail.

This patch changes clang to realize if the executable it found was
the llvm-driver, in which case it will prepend "clang" to the args.
Unconditionally doin'g "clang" is safe because it will only ever
re-invoke itself in cc1 mode, and never need to specify, clang++,
etc.

Diff Detail

Event Timeline

abrachet created this revision.Oct 3 2022, 2:58 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 3 2022, 2:58 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
abrachet requested review of this revision.Oct 3 2022, 2:59 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 3 2022, 2:59 PM
phosek added inline comments.Oct 6 2022, 12:58 AM
llvm/lib/Support/LLVMDriver.cpp
11 ↗(On Diff #464828)

I'd prefer if this variable was a constant because there's no reason why should ever be changed at runtime.

Rather than defining it here, could we instead define it in llvm/tools/llvm-driver/llvm-driver.cpp and llvm/cmake/driver-template.cpp.in as constant that's initialized to true and false respectively.

abrachet updated this revision to Diff 465777.Oct 6 2022, 10:04 AM

Make llvm::IsLLVMDriver const

abrachet marked an inline comment as done.Oct 6 2022, 10:04 AM
abrachet added inline comments.
llvm/lib/Support/LLVMDriver.cpp
11 ↗(On Diff #464828)

Nice, I like that, thanks

abrachet updated this revision to Diff 467989.Oct 14 2022, 7:03 PM
abrachet marked an inline comment as done.
abrachet retitled this revision from [WIP][llvm-driver] Fix clang -fno-integrated-cc1 when invoked from the llvm driver to [llvm-driver] Fix clang -fno-integrated-cc1 when invoked from the llvm driver.
abrachet edited the summary of this revision. (Show Details)
phosek added inline comments.Oct 18 2022, 11:11 PM
clang/lib/Driver/ToolChains/Clang.cpp
5005

Instead of storing a boolean and then duplicating this check and hardcoding the name "clang" in multiple places, we could store the name in the Driver (for example as DriverName) and default it to null. It'd be a responsibility of cc1gen_reproducer_main.cpp and driver.cpp to set it.

abrachet updated this revision to Diff 470218.Oct 24 2022, 10:50 AM
abrachet marked an inline comment as done.
abrachet added inline comments.
clang/lib/Driver/ToolChains/Clang.cpp
5005

Sure

naive question, but... what if the llvm-driver special cased -cc1 as a tool? & then clang wouldn't have to do anything special?

abrachet marked an inline comment as done.Oct 27 2022, 3:47 PM

naive question, but... what if the llvm-driver special cased -cc1 as a tool? & then clang wouldn't have to do anything special?

Not a naive question at all. I had actually thought about this option too and listed it as one in this patch when it was a WIP, ultimately we thought that maybe it was too hacky, though so too is this patch. I've created D136895 so that we can compare and contrast.

It's certainly a lot cleaner to just touch the llvm-driver binary and it's nice to not have to touch clang's Job handling. What do folks think?

I've also added D137800 which is very similar to this patch except it doesn't hardcode "clang" and relies on getting that from the driver

abrachet abandoned this revision.Jun 26 2023, 6:50 AM

Went a different direction