[all-commits] [llvm/llvm-project] 04b419: [Driver] Make "upgrade" of -include to include-pch...

Sam McCall via All-commits all-commits at lists.llvm.org
Thu May 5 07:47:35 PDT 2022

  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 04b419048955fc33718ba97e79f3558b6a27830e
  Author: Sam McCall <sam.mccall at gmail.com>
  Date:   2022-05-05 (Thu, 05 May 2022)

  Changed paths:
    M clang-tools-extra/clangd/Compiler.cpp
    M clang/include/clang/Driver/Driver.h
    M clang/include/clang/Frontend/Utils.h
    M clang/lib/Driver/Driver.cpp
    M clang/lib/Driver/ToolChains/Clang.cpp
    M clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
    M clang/unittests/Frontend/UtilsTest.cpp

  Log Message:
  [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

More information about the All-commits mailing list