From 04b419048955fc33718ba97e79f3558b6a27830e Mon Sep 17 00:00:00 2001 From: Sam McCall Date: Thu, 5 May 2022 01:15:28 +0200 Subject: [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/lib/Frontend/CreateInvocationFromCommandLine.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'clang/lib/Frontend/CreateInvocationFromCommandLine.cpp') diff --git a/clang/lib/Frontend/CreateInvocationFromCommandLine.cpp b/clang/lib/Frontend/CreateInvocationFromCommandLine.cpp index dee7a91..2a98aab 100644 --- a/clang/lib/Frontend/CreateInvocationFromCommandLine.cpp +++ b/clang/lib/Frontend/CreateInvocationFromCommandLine.cpp @@ -48,6 +48,7 @@ clang::createInvocation(ArrayRef ArgList, // Don't check that inputs exist, they may have been remapped. TheDriver.setCheckInputsExist(false); + TheDriver.setProbePrecompiled(Opts.ProbePrecompiled); std::unique_ptr C(TheDriver.BuildCompilation(Args)); if (!C) @@ -107,8 +108,8 @@ clang::createInvocation(ArrayRef ArgList, std::unique_ptr clang::createInvocationFromCommandLine( ArrayRef Args, IntrusiveRefCntPtr Diags, IntrusiveRefCntPtr VFS, bool ShouldRecoverOnErrors, - std::vector *CC1Args) { + std::vector *CC1Args, bool ProbePrecompiled) { return createInvocation( - Args, - CreateInvocationOptions{Diags, VFS, ShouldRecoverOnErrors, CC1Args}); + Args, CreateInvocationOptions{Diags, VFS, ShouldRecoverOnErrors, + ProbePrecompiled, CC1Args}); } -- cgit v1.1