summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp14
-rw-r--r--clang/lib/Frontend/PCHContainerOperations.cpp6
-rw-r--r--clang/lib/Frontend/SerializedDiagnosticReader.cpp11
-rw-r--r--clang/lib/Serialization/ASTReader.cpp23
-rw-r--r--clang/lib/Serialization/GlobalModuleIndex.cpp9
-rw-r--r--clang/lib/Serialization/ModuleManager.cpp5
6 files changed, 30 insertions, 38 deletions
diff --git a/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp b/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
index 42a9782219c..baf7811eeda 100644
--- a/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
+++ b/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
@@ -312,8 +312,9 @@ ObjectFilePCHContainerWriter::CreatePCHContainerGenerator(
CI, MainFileName, OutputFileName, std::move(OS), Buffer);
}
-void ObjectFilePCHContainerReader::ExtractPCH(
- llvm::MemoryBufferRef Buffer, llvm::BitstreamReader &StreamFile) const {
+StringRef
+ObjectFilePCHContainerReader::ExtractPCH(llvm::MemoryBufferRef Buffer) const {
+ StringRef PCH;
auto OFOrErr = llvm::object::ObjectFile::createObjectFile(Buffer);
if (OFOrErr) {
auto &OF = OFOrErr.get();
@@ -323,10 +324,8 @@ void ObjectFilePCHContainerReader::ExtractPCH(
StringRef Name;
Section.getName(Name);
if ((!IsCOFF && Name == "__clangast") || (IsCOFF && Name == "clangast")) {
- StringRef Buf;
- Section.getContents(Buf);
- StreamFile = llvm::BitstreamReader(Buf);
- return;
+ Section.getContents(PCH);
+ return PCH;
}
}
}
@@ -334,8 +333,9 @@ void ObjectFilePCHContainerReader::ExtractPCH(
if (EIB.convertToErrorCode() ==
llvm::object::object_error::invalid_file_type)
// As a fallback, treat the buffer as a raw AST.
- StreamFile = llvm::BitstreamReader(Buffer);
+ PCH = Buffer.getBuffer();
else
EIB.log(llvm::errs());
});
+ return PCH;
}
diff --git a/clang/lib/Frontend/PCHContainerOperations.cpp b/clang/lib/Frontend/PCHContainerOperations.cpp
index 2c867e7c648..eebebf327a1 100644
--- a/clang/lib/Frontend/PCHContainerOperations.cpp
+++ b/clang/lib/Frontend/PCHContainerOperations.cpp
@@ -58,9 +58,9 @@ std::unique_ptr<ASTConsumer> RawPCHContainerWriter::CreatePCHContainerGenerator(
return llvm::make_unique<RawPCHContainerGenerator>(std::move(OS), Buffer);
}
-void RawPCHContainerReader::ExtractPCH(
- llvm::MemoryBufferRef Buffer, llvm::BitstreamReader &StreamFile) const {
- StreamFile = llvm::BitstreamReader(Buffer);
+StringRef
+RawPCHContainerReader::ExtractPCH(llvm::MemoryBufferRef Buffer) const {
+ return Buffer.getBuffer();
}
PCHContainerOperations::PCHContainerOperations() {
diff --git a/clang/lib/Frontend/SerializedDiagnosticReader.cpp b/clang/lib/Frontend/SerializedDiagnosticReader.cpp
index aefd0f8fbb0..c4461d452e7 100644
--- a/clang/lib/Frontend/SerializedDiagnosticReader.cpp
+++ b/clang/lib/Frontend/SerializedDiagnosticReader.cpp
@@ -24,8 +24,8 @@ std::error_code SerializedDiagnosticReader::readDiagnostics(StringRef File) {
if (!Buffer)
return SDError::CouldNotLoad;
- llvm::BitstreamReader StreamFile(**Buffer);
- llvm::BitstreamCursor Stream(StreamFile);
+ llvm::BitstreamCursor Stream(**Buffer);
+ Optional<llvm::BitstreamBlockInfo> BlockInfo;
// Sniff for the signature.
if (Stream.Read(8) != 'D' ||
@@ -41,10 +41,13 @@ std::error_code SerializedDiagnosticReader::readDiagnostics(StringRef File) {
std::error_code EC;
switch (Stream.ReadSubBlockID()) {
- case llvm::bitc::BLOCKINFO_BLOCK_ID:
- if (Stream.ReadBlockInfoBlock())
+ case llvm::bitc::BLOCKINFO_BLOCK_ID: {
+ BlockInfo = Stream.ReadBlockInfoBlock();
+ if (!BlockInfo)
return SDError::MalformedBlockInfoBlock;
+ Stream.setBlockInfo(&*BlockInfo);
continue;
+ }
case BLOCK_META:
if ((EC = readMetaBlock(Stream)))
return EC;
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index 650c46e9ff0..5c875ee7319 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -1711,7 +1711,7 @@ void ASTReader::ReadDefinedMacros() {
BitstreamCursor &MacroCursor = I->MacroCursor;
// If there was no preprocessor block, skip this file.
- if (!MacroCursor.getBitStreamReader())
+ if (MacroCursor.getBitcodeBytes().empty())
continue;
BitstreamCursor Cursor = MacroCursor;
@@ -3798,7 +3798,7 @@ ASTReader::ASTReadResult ASTReader::ReadAST(StringRef FileName,
return Success;
}
-static ASTFileSignature readASTFileSignature(llvm::BitstreamReader &StreamFile);
+static ASTFileSignature readASTFileSignature(StringRef PCH);
/// \brief Whether \p Stream starts with the AST/PCH file magic number 'CPCH'.
static bool startsWithASTFileMagic(BitstreamCursor &Stream) {
@@ -3885,8 +3885,7 @@ ASTReader::ReadASTCore(StringRef FileName,
ModuleFile &F = *M;
BitstreamCursor &Stream = F.Stream;
- PCHContainerRdr.ExtractPCH(F.Buffer->getMemBufferRef(), F.StreamFile);
- Stream.init(&F.StreamFile);
+ Stream = BitstreamCursor(PCHContainerRdr.ExtractPCH(*F.Buffer));
F.SizeInBits = F.Buffer->getBufferSize() * 8;
// Sniff for the signature.
@@ -4175,10 +4174,10 @@ void ASTReader::finalizeForWriting() {
// Nothing to do for now.
}
-/// \brief Reads and return the signature record from \p StreamFile's control
-/// block, or else returns 0.
-static ASTFileSignature readASTFileSignature(llvm::BitstreamReader &StreamFile){
- BitstreamCursor Stream(StreamFile);
+/// \brief Reads and return the signature record from \p PCH's control block, or
+/// else returns 0.
+static ASTFileSignature readASTFileSignature(StringRef PCH) {
+ BitstreamCursor Stream(PCH);
if (!startsWithASTFileMagic(Stream))
return 0;
@@ -4216,9 +4215,7 @@ std::string ASTReader::getOriginalSourceFile(
}
// Initialize the stream
- llvm::BitstreamReader StreamFile;
- PCHContainerRdr.ExtractPCH((*Buffer)->getMemBufferRef(), StreamFile);
- BitstreamCursor Stream(StreamFile);
+ BitstreamCursor Stream(PCHContainerRdr.ExtractPCH(**Buffer));
// Sniff for the signature.
if (!startsWithASTFileMagic(Stream)) {
@@ -4318,9 +4315,7 @@ bool ASTReader::readASTFileControlBlock(
}
// Initialize the stream
- llvm::BitstreamReader StreamFile;
- PCHContainerRdr.ExtractPCH((*Buffer)->getMemBufferRef(), StreamFile);
- BitstreamCursor Stream(StreamFile);
+ BitstreamCursor Stream(PCHContainerRdr.ExtractPCH(**Buffer));
// Sniff for the signature.
if (!startsWithASTFileMagic(Stream))
diff --git a/clang/lib/Serialization/GlobalModuleIndex.cpp b/clang/lib/Serialization/GlobalModuleIndex.cpp
index e55ed40b227..9f986d54a98 100644
--- a/clang/lib/Serialization/GlobalModuleIndex.cpp
+++ b/clang/lib/Serialization/GlobalModuleIndex.cpp
@@ -245,11 +245,8 @@ GlobalModuleIndex::readIndex(StringRef Path) {
return std::make_pair(nullptr, EC_NotFound);
std::unique_ptr<llvm::MemoryBuffer> Buffer = std::move(BufferOrErr.get());
- /// \brief The bitstream reader from which we'll read the AST file.
- llvm::BitstreamReader Reader(*Buffer);
-
/// \brief The main bitstream cursor for the main block.
- llvm::BitstreamCursor Cursor(Reader);
+ llvm::BitstreamCursor Cursor(*Buffer);
// Sniff for the signature.
if (Cursor.Read(8) != 'B' ||
@@ -503,9 +500,7 @@ bool GlobalModuleIndexBuilder::loadModuleFile(const FileEntry *File) {
}
// Initialize the input stream
- llvm::BitstreamReader InStreamFile;
- PCHContainerRdr.ExtractPCH((*Buffer)->getMemBufferRef(), InStreamFile);
- llvm::BitstreamCursor InStream(InStreamFile);
+ llvm::BitstreamCursor InStream(PCHContainerRdr.ExtractPCH(**Buffer));
// Sniff for the signature.
if (InStream.Read(8) != 'C' ||
diff --git a/clang/lib/Serialization/ModuleManager.cpp b/clang/lib/Serialization/ModuleManager.cpp
index 0a176f6fa80..e50dcaab2f6 100644
--- a/clang/lib/Serialization/ModuleManager.cpp
+++ b/clang/lib/Serialization/ModuleManager.cpp
@@ -135,15 +135,14 @@ ModuleManager::addModule(StringRef FileName, ModuleKind Type,
}
// Initialize the stream.
- PCHContainerRdr.ExtractPCH(ModuleEntry->Buffer->getMemBufferRef(),
- ModuleEntry->StreamFile);
+ ModuleEntry->Data = PCHContainerRdr.ExtractPCH(*ModuleEntry->Buffer);
}
if (ExpectedSignature) {
// If we've not read the control block yet, read the signature eagerly now
// so that we can check it.
if (!ModuleEntry->Signature)
- ModuleEntry->Signature = ReadSignature(ModuleEntry->StreamFile);
+ ModuleEntry->Signature = ReadSignature(ModuleEntry->Data);
if (ModuleEntry->Signature != ExpectedSignature) {
ErrorStr = ModuleEntry->Signature ? "signature mismatch"
OpenPOWER on IntegriCloud