[Driver] Make "upgrade" of -include to include-pch optional; disable in clangd
authorSam McCall <sam.mccall@gmail.com>
Wed, 4 May 2022 23:15:28 +0000 (01:15 +0200)
committerSam McCall <sam.mccall@gmail.com>
Thu, 5 May 2022 14:47:17 +0000 (16:47 +0200)
commit04b419048955fc33718ba97e79f3558b6a27830e
tree1a54c8178fbec147b5109471bb2549f842a1aed8
parent042a7a5f0da8beb89cbbfe2f1c3a155e654d9375
[Driver] Make "upgrade" of -include to include-pch optional; disable in clangd

If clang is passed "-include foo.h", it will rewrite to "-include-pch foo.h.pch"
before passing it to cc1, if foo.h.pch exists.

Existence is checked, but validity is not. This is probably a reasonable
assumption for the compiler itself, but not for clang-based tools where the
actual compiler may be a different version of clang, or even GCC.
In the end, we lose our -include, we gain a -include-pch that can't be used,
and the file often fails to parse.

I would like to turn this off for all non-clang invocations (i.e.
createInvocationFromCommandLine), but we have explicit tests of this behavior
for libclang and I can't work out the implications of changing it.

Instead this patch:
 - makes it optional in the driver, default on (no change)
 - makes it optional in createInvocationFromCommandLine, default on (no change)
 - changes driver to do IO through the VFS so it can be tested
 - tests the option
 - turns the option off in clangd where the problem was reported

Subsequent patches should make libclang opt in explicitly and flip the default
for all other tools. It's probably also time to extract an options struct
for createInvocationFromCommandLine.

Fixes https://github.com/clangd/clangd/issues/856
Fixes https://github.com/clangd/vscode-clangd/issues/324

Differential Revision: https://reviews.llvm.org/D124970
clang-tools-extra/clangd/Compiler.cpp
clang/include/clang/Driver/Driver.h
clang/include/clang/Frontend/Utils.h
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
clang/unittests/Frontend/UtilsTest.cpp