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
}

0 commit comments

Comments
 (0)