diff options
author | Kadir Cetinkaya <kadircet@google.com> | 2023-02-08 19:53:55 +0100 |
---|---|---|
committer | Kadir Cetinkaya <kadircet@google.com> | 2023-02-13 09:49:13 +0100 |
commit | 19659b5f0dd1a1dcf745cf058d042ada2d4ff061 (patch) | |
tree | 3ad60b9aab341a3b241ad917c9fc7b522b84ca77 | |
parent | fae01d175a29270ec01211d3988c7ae57ddabfd3 (diff) | |
download | llvm-19659b5f0dd1a1dcf745cf058d042ada2d4ff061.zip llvm-19659b5f0dd1a1dcf745cf058d042ada2d4ff061.tar.gz llvm-19659b5f0dd1a1dcf745cf058d042ada2d4ff061.tar.bz2 |
[clangd] Drop includes from disabled PP regions in preamble patch
In rest of the clangd functionality we treat these includes as
non-existent. Do so under preamble patching.
Depends on D143197
Differential Revision: https://reviews.llvm.org/D143597
-rw-r--r-- | clang-tools-extra/clangd/Preamble.cpp | 15 | ||||
-rw-r--r-- | clang-tools-extra/clangd/unittests/PreambleTests.cpp | 9 |
2 files changed, 17 insertions, 7 deletions
diff --git a/clang-tools-extra/clangd/Preamble.cpp b/clang-tools-extra/clangd/Preamble.cpp index cdb8db1..f99c414 100644 --- a/clang-tools-extra/clangd/Preamble.cpp +++ b/clang-tools-extra/clangd/Preamble.cpp @@ -685,13 +685,16 @@ PreamblePatch PreamblePatch::create(llvm::StringRef FileName, // Include already present in the baseline preamble. Set resolved path and // put into preamble includes. if (It != ExistingIncludes.end()) { - auto &PatchedInc = PP.PreambleIncludes.emplace_back(); - // Copy everything from existing include, apart from the location, when - // it's coming from baseline preamble. - if (It->second) + if (It->second) { + // If this header is included in an active region of the baseline + // preamble, preserve it. + auto &PatchedInc = PP.PreambleIncludes.emplace_back(); + // Copy everything from existing include, apart from the location, + // when it's coming from baseline preamble. PatchedInc = *It->second; - PatchedInc.HashLine = Inc.HashLine; - PatchedInc.HashOffset = Inc.HashOffset; + PatchedInc.HashLine = Inc.HashLine; + PatchedInc.HashOffset = Inc.HashOffset; + } continue; } // Include is new in the modified preamble. Inject it into the patch and diff --git a/clang-tools-extra/clangd/unittests/PreambleTests.cpp b/clang-tools-extra/clangd/unittests/PreambleTests.cpp index ac46bfd..ae353f9 100644 --- a/clang-tools-extra/clangd/unittests/PreambleTests.cpp +++ b/clang-tools-extra/clangd/unittests/PreambleTests.cpp @@ -170,6 +170,9 @@ TEST(PreamblePatchTest, PatchesPreambleIncludes) { auto TU = TestTU::withCode(R"cpp( #include "a.h" // IWYU pragma: keep #include "c.h" + #ifdef FOO + #include "d.h" + #endif )cpp"); TU.AdditionalFiles["a.h"] = "#include \"b.h\""; TU.AdditionalFiles["b.h"] = ""; @@ -178,10 +181,14 @@ TEST(PreamblePatchTest, PatchesPreambleIncludes) { auto BaselinePreamble = buildPreamble( TU.Filename, *buildCompilerInvocation(PI, Diags), PI, true, nullptr); // We drop c.h from modified and add a new header. Since the latter is patched - // we should only get a.h in preamble includes. + // we should only get a.h in preamble includes. d.h shouldn't be part of the + // preamble, as it's coming from a disabled region. TU.Code = R"cpp( #include "a.h" #include "b.h" + #ifdef FOO + #include "d.h" + #endif )cpp"; auto PP = PreamblePatch::createFullPatch(testPath(TU.Filename), TU.inputs(FS), *BaselinePreamble); |