r285773 - Bitcode: Change reader interface to take memory buffers.
Peter Collingbourne via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 1 17:08:21 PDT 2016
Author: pcc
Date: Tue Nov 1 19:08:19 2016
New Revision: 285773
URL: http://llvm.org/viewvc/llvm-project?rev=285773&view=rev
Log:
Bitcode: Change reader interface to take memory buffers.
As proposed on llvm-dev:
http://lists.llvm.org/pipermail/llvm-dev/2016-October/106595.html
This change also fixes an API oddity where BitstreamCursor::Read() would
return zero for the first read past the end of the bitstream, but would
report_fatal_error for subsequent reads. Now we always report_fatal_error
for all reads past the end. Updated clients to check for the end of the
bitstream before reading from it.
I also needed to add padding to the invalid bitcode tests in
test/Bitcode/. This is because the streaming interface was not checking that
the file size is a multiple of 4.
Differential Revision: https://reviews.llvm.org/D26219
Modified:
cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
cfe/trunk/lib/Frontend/PCHContainerOperations.cpp
cfe/trunk/lib/Frontend/SerializedDiagnosticReader.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/GlobalModuleIndex.cpp
Modified: cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp?rev=285773&r1=285772&r2=285773&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp (original)
+++ cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp Tue Nov 1 19:08:19 2016
@@ -325,8 +325,8 @@ void ObjectFilePCHContainerReader::Extra
if ((!IsCOFF && Name == "__clangast") || (IsCOFF && Name == "clangast")) {
StringRef Buf;
Section.getContents(Buf);
- return StreamFile.init((const unsigned char *)Buf.begin(),
- (const unsigned char *)Buf.end());
+ StreamFile = llvm::BitstreamReader(Buf);
+ return;
}
}
}
@@ -334,8 +334,7 @@ void ObjectFilePCHContainerReader::Extra
if (EIB.convertToErrorCode() ==
llvm::object::object_error::invalid_file_type)
// As a fallback, treat the buffer as a raw AST.
- StreamFile.init((const unsigned char *)Buffer.getBufferStart(),
- (const unsigned char *)Buffer.getBufferEnd());
+ StreamFile = llvm::BitstreamReader(Buffer);
else
EIB.log(llvm::errs());
});
Modified: cfe/trunk/lib/Frontend/PCHContainerOperations.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHContainerOperations.cpp?rev=285773&r1=285772&r2=285773&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHContainerOperations.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHContainerOperations.cpp Tue Nov 1 19:08:19 2016
@@ -60,8 +60,7 @@ std::unique_ptr<ASTConsumer> RawPCHConta
void RawPCHContainerReader::ExtractPCH(
llvm::MemoryBufferRef Buffer, llvm::BitstreamReader &StreamFile) const {
- StreamFile.init((const unsigned char *)Buffer.getBufferStart(),
- (const unsigned char *)Buffer.getBufferEnd());
+ StreamFile = llvm::BitstreamReader(Buffer);
}
PCHContainerOperations::PCHContainerOperations() {
Modified: cfe/trunk/lib/Frontend/SerializedDiagnosticReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/SerializedDiagnosticReader.cpp?rev=285773&r1=285772&r2=285773&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/SerializedDiagnosticReader.cpp (original)
+++ cfe/trunk/lib/Frontend/SerializedDiagnosticReader.cpp Tue Nov 1 19:08:19 2016
@@ -24,10 +24,7 @@ std::error_code SerializedDiagnosticRead
if (!Buffer)
return SDError::CouldNotLoad;
- llvm::BitstreamReader StreamFile;
- StreamFile.init((const unsigned char *)(*Buffer)->getBufferStart(),
- (const unsigned char *)(*Buffer)->getBufferEnd());
-
+ llvm::BitstreamReader StreamFile(**Buffer);
llvm::BitstreamCursor Stream(StreamFile);
// Sniff for the signature.
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=285773&r1=285772&r2=285773&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Tue Nov 1 19:08:19 2016
@@ -3802,7 +3802,8 @@ static ASTFileSignature readASTFileSigna
/// \brief Whether \p Stream starts with the AST/PCH file magic number 'CPCH'.
static bool startsWithASTFileMagic(BitstreamCursor &Stream) {
- return Stream.Read(8) == 'C' &&
+ return Stream.canSkipToPos(4) &&
+ Stream.Read(8) == 'C' &&
Stream.Read(8) == 'P' &&
Stream.Read(8) == 'C' &&
Stream.Read(8) == 'H';
Modified: cfe/trunk/lib/Serialization/GlobalModuleIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/GlobalModuleIndex.cpp?rev=285773&r1=285772&r2=285773&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/GlobalModuleIndex.cpp (original)
+++ cfe/trunk/lib/Serialization/GlobalModuleIndex.cpp Tue Nov 1 19:08:19 2016
@@ -246,8 +246,7 @@ GlobalModuleIndex::readIndex(StringRef P
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((const unsigned char *)Buffer->getBufferStart(),
- (const unsigned char *)Buffer->getBufferEnd());
+ llvm::BitstreamReader Reader(*Buffer);
/// \brief The main bitstream cursor for the main block.
llvm::BitstreamCursor Cursor(Reader);
More information about the cfe-commits
mailing list