[all-commits] [llvm/llvm-project] 0683a1: [clangd] Adjust compile flags so they work when ap...
Sam McCall via All-commits
all-commits at lists.llvm.org
Tue Jan 4 07:10:42 PST 2022
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 0683a1e588ade04bba2572e5ab6cf1361ed392d4
https://github.com/llvm/llvm-project/commit/0683a1e588ade04bba2572e5ab6cf1361ed392d4
Author: Sam McCall <sam.mccall at gmail.com>
Date: 2022-01-04 (Tue, 04 Jan 2022)
Changed paths:
M clang-tools-extra/clangd/CompileCommands.cpp
M clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
Log Message:
-----------
[clangd] Adjust compile flags so they work when applied to other file(type)s.
It's reasonable to want to use the command from one file to compile another.
In particular, the command from a translation unit to parse a related header:
{"file": "foo.h", "command": "clang foo.cpp"}
This is largely what InterpolatingCompilationDatabase tries to do.
To do this correctly can require nontrivial changes to the argv, because the
file extension affects semantics. e.g. here we must add "-x c++header".
When external tools compile commands for different files, we should apply the
same adjustments. This is better than telling people to "fix their tools":
- simple e.g. python scripts shouldn't have to interpret clang argv
- this is a good way to represent the intent "parse header X in the context of
file Y", which can work even if X is not self-contained. clangd does not
support this today, but some other tools do, and we may one day.
This issue is discussed in https://github.com/clangd/clangd/issues/519
Differential Revision: https://reviews.llvm.org/D116167
More information about the All-commits
mailing list