Skip to content

Commit b3bb7aa

Browse files
authored
Merge pull request #10173 from benlangmuir/cherry-pick-144790713-6.1
Remove extraneous dependencies from libclangDependencyScanning to fix regression in clangd size
2 parents fc8af60 + c92dae6 commit b3bb7aa

File tree

18 files changed

+98
-74
lines changed

18 files changed

+98
-74
lines changed

clang/include/clang/CodeGen/ObjectFilePCHContainerOperations.h renamed to clang/include/clang/CodeGen/ObjectFilePCHContainerWriter.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- CodeGen/ObjectFilePCHContainerOperations.h - ------------*- C++ -*-===//
1+
//===-- CodeGen/ObjectFilePCHContainerWriter.h ------------------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -29,14 +29,6 @@ class ObjectFilePCHContainerWriter : public PCHContainerWriter {
2929
std::shared_ptr<PCHBuffer> Buffer) const override;
3030
};
3131

32-
/// A PCHContainerReader implementation that uses LLVM to
33-
/// wraps Clang modules inside a COFF, ELF, or Mach-O container.
34-
class ObjectFilePCHContainerReader : public PCHContainerReader {
35-
ArrayRef<StringRef> getFormats() const override;
36-
37-
/// Returns the serialized AST inside the PCH container Buffer.
38-
StringRef ExtractPCH(llvm::MemoryBufferRef Buffer) const override;
39-
};
4032
}
4133

4234
#endif
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===-- Serialization/ObjectFilePCHContainerReader.h ------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_CLANG_SERIALIZATION_OBJECTFILEPCHCONTAINERREADER_H
10+
#define LLVM_CLANG_SERIALIZATION_OBJECTFILEPCHCONTAINERREADER_H
11+
12+
#include "clang/Frontend/PCHContainerOperations.h"
13+
14+
namespace clang {
15+
/// A PCHContainerReader implementation that uses LLVM to
16+
/// wraps Clang modules inside a COFF, ELF, or Mach-O container.
17+
class ObjectFilePCHContainerReader : public PCHContainerReader {
18+
ArrayRef<StringRef> getFormats() const override;
19+
20+
/// Returns the serialized AST inside the PCH container Buffer.
21+
StringRef ExtractPCH(llvm::MemoryBufferRef Buffer) const override;
22+
};
23+
} // namespace clang
24+
25+
#endif

clang/lib/CodeGen/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ add_clang_library(clangCodeGen
110110
MacroPPCallbacks.cpp
111111
MicrosoftCXXABI.cpp
112112
ModuleBuilder.cpp
113-
ObjectFilePCHContainerOperations.cpp
113+
ObjectFilePCHContainerWriter.cpp
114114
PatternInit.cpp
115115
SanitizerMetadata.cpp
116116
SwiftCallingConv.cpp

clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp renamed to clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
//===--- ObjectFilePCHContainerOperations.cpp -----------------------------===//
1+
//===--- ObjectFilePCHContainerWriter.cpp -----------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
9+
#include "clang/CodeGen/ObjectFilePCHContainerWriter.h"
1010
#include "CGDebugInfo.h"
1111
#include "CodeGenModule.h"
1212
#include "clang/AST/ASTContext.h"
@@ -360,46 +360,3 @@ ObjectFilePCHContainerWriter::CreatePCHContainerGenerator(
360360
return std::make_unique<PCHContainerGenerator>(
361361
CI, MainFileName, OutputFileName, std::move(OS), Buffer);
362362
}
363-
364-
ArrayRef<StringRef> ObjectFilePCHContainerReader::getFormats() const {
365-
static StringRef Formats[] = {"obj", "raw"};
366-
return Formats;
367-
}
368-
369-
StringRef
370-
ObjectFilePCHContainerReader::ExtractPCH(llvm::MemoryBufferRef Buffer) const {
371-
StringRef PCH;
372-
auto OFOrErr = llvm::object::ObjectFile::createObjectFile(Buffer);
373-
if (OFOrErr) {
374-
auto &OF = OFOrErr.get();
375-
bool IsCOFF = isa<llvm::object::COFFObjectFile>(*OF);
376-
// Find the clang AST section in the container.
377-
for (auto &Section : OF->sections()) {
378-
StringRef Name;
379-
if (Expected<StringRef> NameOrErr = Section.getName())
380-
Name = *NameOrErr;
381-
else
382-
consumeError(NameOrErr.takeError());
383-
384-
if ((!IsCOFF && Name == "__clangast") || (IsCOFF && Name == "clangast")) {
385-
if (Expected<StringRef> E = Section.getContents())
386-
return *E;
387-
else {
388-
handleAllErrors(E.takeError(), [&](const llvm::ErrorInfoBase &EIB) {
389-
EIB.log(llvm::errs());
390-
});
391-
return "";
392-
}
393-
}
394-
}
395-
}
396-
handleAllErrors(OFOrErr.takeError(), [&](const llvm::ErrorInfoBase &EIB) {
397-
if (EIB.convertToErrorCode() ==
398-
llvm::object::object_error::invalid_file_type)
399-
// As a fallback, treat the buffer as a raw AST.
400-
PCH = Buffer.getBuffer();
401-
else
402-
EIB.log(llvm::errs());
403-
});
404-
return PCH;
405-
}

clang/lib/Interpreter/Interpreter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "clang/Basic/TargetInfo.h"
2727
#include "clang/CodeGen/CodeGenAction.h"
2828
#include "clang/CodeGen/ModuleBuilder.h"
29-
#include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
29+
#include "clang/CodeGen/ObjectFilePCHContainerWriter.h"
3030
#include "clang/Driver/Compilation.h"
3131
#include "clang/Driver/Driver.h"
3232
#include "clang/Driver/Job.h"
@@ -38,6 +38,7 @@
3838
#include "clang/Interpreter/Value.h"
3939
#include "clang/Lex/PreprocessorOptions.h"
4040
#include "clang/Sema/Lookup.h"
41+
#include "clang/Serialization/ObjectFilePCHContainerReader.h"
4142
#include "llvm/ExecutionEngine/JITSymbol.h"
4243
#include "llvm/ExecutionEngine/Orc/LLJIT.h"
4344
#include "llvm/IR/Module.h"

clang/lib/Interpreter/InterpreterUtils.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "clang/AST/TypeVisitor.h"
1919
#include "clang/Basic/TargetInfo.h"
2020
#include "clang/CodeGen/ModuleBuilder.h"
21-
#include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
2221
#include "clang/Driver/Compilation.h"
2322
#include "clang/Driver/Driver.h"
2423
#include "clang/Driver/Job.h"

clang/lib/Serialization/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
set(LLVM_LINK_COMPONENTS
22
BitReader
33
BitstreamReader
4+
Object
45
Support
56
TargetParser
67
)
@@ -21,6 +22,7 @@ add_clang_library(clangSerialization
2122
ModuleFileExtension.cpp
2223
ModuleManager.cpp
2324
PCHContainerOperations.cpp
25+
ObjectFilePCHContainerReader.cpp
2426

2527
ADDITIONAL_HEADERS
2628
ASTCommon.h
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//===--- ObjectFilePCHContainerReader.cpp ---------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "clang/Serialization/ObjectFilePCHContainerReader.h"
10+
#include "llvm/Object/COFF.h"
11+
#include "llvm/Object/ObjectFile.h"
12+
13+
using namespace clang;
14+
15+
ArrayRef<StringRef> ObjectFilePCHContainerReader::getFormats() const {
16+
static StringRef Formats[] = {"obj", "raw"};
17+
return Formats;
18+
}
19+
20+
StringRef
21+
ObjectFilePCHContainerReader::ExtractPCH(llvm::MemoryBufferRef Buffer) const {
22+
StringRef PCH;
23+
auto OFOrErr = llvm::object::ObjectFile::createObjectFile(Buffer);
24+
if (OFOrErr) {
25+
auto &OF = OFOrErr.get();
26+
bool IsCOFF = isa<llvm::object::COFFObjectFile>(*OF);
27+
// Find the clang AST section in the container.
28+
for (auto &Section : OF->sections()) {
29+
StringRef Name;
30+
if (Expected<StringRef> NameOrErr = Section.getName())
31+
Name = *NameOrErr;
32+
else
33+
consumeError(NameOrErr.takeError());
34+
35+
if ((!IsCOFF && Name == "__clangast") || (IsCOFF && Name == "clangast")) {
36+
if (Expected<StringRef> E = Section.getContents())
37+
return *E;
38+
else {
39+
handleAllErrors(E.takeError(), [&](const llvm::ErrorInfoBase &EIB) {
40+
EIB.log(llvm::errs());
41+
});
42+
return "";
43+
}
44+
}
45+
}
46+
}
47+
handleAllErrors(OFOrErr.takeError(), [&](const llvm::ErrorInfoBase &EIB) {
48+
if (EIB.convertToErrorCode() ==
49+
llvm::object::object_error::invalid_file_type)
50+
// As a fallback, treat the buffer as a raw AST.
51+
PCH = Buffer.getBuffer();
52+
else
53+
EIB.log(llvm::errs());
54+
});
55+
return PCH;
56+
}

clang/lib/Tooling/DependencyScanning/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
set(LLVM_LINK_COMPONENTS
2-
${LLVM_TARGETS_TO_BUILD}
32
Core
43
Option
54
Support
@@ -25,7 +24,6 @@ add_clang_library(clangDependencyScanning
2524
clangAST
2625
clangBasic
2726
clangCAS
28-
clangCodeGen
2927
clangDriver
3028
clangFrontend
3129
clangLex

clang/lib/Tooling/DependencyScanning/DependencyScanningService.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "llvm/CAS/ActionCache.h"
1111
#include "llvm/CAS/CachingOnDiskFileSystem.h"
1212
#include "llvm/CAS/ObjectStore.h"
13-
#include "llvm/Support/TargetSelect.h"
1413

1514
using namespace clang;
1615
using namespace tooling;
@@ -27,10 +26,4 @@ DependencyScanningService::DependencyScanningService(
2726
SharedFS(std::move(SharedFS)) {
2827
if (!this->SharedFS)
2928
SharedCache.emplace();
30-
31-
// Initialize targets for object file support.
32-
llvm::InitializeAllTargets();
33-
llvm::InitializeAllTargetMCs();
34-
llvm::InitializeAllAsmPrinters();
35-
llvm::InitializeAllAsmParsers();
3629
}

clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "clang/Basic/DiagnosticDriver.h"
1212
#include "clang/Basic/DiagnosticFrontend.h"
1313
#include "clang/Basic/DiagnosticSerialization.h"
14-
#include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
1514
#include "clang/Driver/Compilation.h"
1615
#include "clang/Driver/Driver.h"
1716
#include "clang/Driver/Job.h"
@@ -24,6 +23,7 @@
2423
#include "clang/Frontend/TextDiagnosticPrinter.h"
2524
#include "clang/Frontend/Utils.h"
2625
#include "clang/Lex/PreprocessorOptions.h"
26+
#include "clang/Serialization/ObjectFilePCHContainerReader.h"
2727
#include "clang/Tooling/DependencyScanning/DependencyScanningService.h"
2828
#include "clang/Tooling/DependencyScanning/ModuleDepCollector.h"
2929
#include "clang/Tooling/DependencyScanning/ScanAndUpdateArgs.h"

clang/tools/c-index-test/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ else()
3636
${INDEXSTORE_LIB}
3737
clangAST
3838
clangBasic
39-
clangCodeGen
4039
clangDependencyScanning
4140
clangDirectoryWatcher
4241
clangFrontend

clang/tools/c-index-test/core_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "clang/AST/Mangle.h"
1414
#include "clang/Basic/LangOptions.h"
1515
#include "clang/Basic/PathRemapper.h"
16-
#include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
1716
#include "clang/Frontend/ASTUnit.h"
1817
#include "clang/Frontend/CompilerInstance.h"
1918
#include "clang/Frontend/CompilerInvocation.h"
@@ -27,6 +26,7 @@
2726
#include "clang/Index/USRGeneration.h"
2827
#include "clang/Lex/Preprocessor.h"
2928
#include "clang/Serialization/ASTReader.h"
29+
#include "clang/Serialization/ObjectFilePCHContainerReader.h"
3030
#include "llvm/ADT/FunctionExtras.h"
3131
#include "llvm/ADT/ScopeExit.h"
3232
#include "llvm/Support/CommandLine.h"

clang/tools/clang-check/ClangCheck.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
//===----------------------------------------------------------------------===//
1717

1818
#include "clang/AST/ASTConsumer.h"
19-
#include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
2019
#include "clang/Driver/Options.h"
2120
#include "clang/Frontend/ASTConsumers.h"
2221
#include "clang/Frontend/CompilerInstance.h"

clang/tools/driver/cc1_main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#include "clang/Basic/Stack.h"
1616
#include "clang/Basic/TargetOptions.h"
17-
#include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
17+
#include "clang/CodeGen/ObjectFilePCHContainerWriter.h"
1818
#include "clang/Config/config.h"
1919
#include "clang/Driver/DriverDiagnostic.h"
2020
#include "clang/Driver/Options.h"
@@ -26,6 +26,7 @@
2626
#include "clang/Frontend/TextDiagnosticPrinter.h"
2727
#include "clang/Frontend/Utils.h"
2828
#include "clang/FrontendTool/Utils.h"
29+
#include "clang/Serialization/ObjectFilePCHContainerReader.h"
2930
#include "llvm/ADT/ScopeExit.h"
3031
#include "llvm/ADT/Statistic.h"
3132
#include "llvm/ADT/StringExtras.h"

clang/tools/driver/cc1depscan_main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "clang/Basic/DiagnosticFrontend.h"
1313
#include "clang/Basic/Stack.h"
1414
#include "clang/Basic/TargetOptions.h"
15-
#include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
15+
#include "clang/CodeGen/ObjectFilePCHContainerWriter.h"
1616
#include "clang/Config/config.h"
1717
#include "clang/Driver/Options.h"
1818
#include "clang/Frontend/CompileJobCacheKey.h"
@@ -22,6 +22,7 @@
2222
#include "clang/Frontend/TextDiagnosticPrinter.h"
2323
#include "clang/Frontend/Utils.h"
2424
#include "clang/FrontendTool/Utils.h"
25+
#include "clang/Serialization/ObjectFilePCHContainerReader.h"
2526
#include "clang/Tooling/DependencyScanning/DependencyScanningService.h"
2627
#include "clang/Tooling/DependencyScanning/DependencyScanningTool.h"
2728
#include "clang/Tooling/DependencyScanning/ScanAndUpdateArgs.h"

lldb/source/Commands/CommandObjectTarget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@
5959
#include "lldb/lldb-enumerations.h"
6060
#include "lldb/lldb-private-enumerations.h"
6161

62-
#include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
6362
#include "clang/Frontend/CompilerInstance.h"
6463
#include "clang/Frontend/CompilerInvocation.h"
6564
#include "clang/Frontend/FrontendActions.h"
65+
#include "clang/Serialization/ObjectFilePCHContainerReader.h"
6666
#include "llvm/ADT/ScopeExit.h"
6767
#include "llvm/ADT/StringRef.h"
6868
#include "llvm/Support/FileSystem.h"

lldb/tools/lldb-instr/Instrument.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#include "clang/AST/AST.h"
22
#include "clang/AST/ASTConsumer.h"
33
#include "clang/AST/RecursiveASTVisitor.h"
4-
#include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
4+
#include "clang/CodeGen/ObjectFilePCHContainerWriter.h"
55
#include "clang/Frontend/ASTConsumers.h"
66
#include "clang/Frontend/CompilerInstance.h"
77
#include "clang/Frontend/FrontendActions.h"
88
#include "clang/Rewrite/Core/Rewriter.h"
9+
#include "clang/Serialization/ObjectFilePCHContainerReader.h"
910
#include "clang/Tooling/CommonOptionsParser.h"
1011
#include "clang/Tooling/Tooling.h"
1112

0 commit comments

Comments
 (0)