Skip to content

Cherry-pick LLVM Bitstream changes #28214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions lib/ClangImporter/SwiftLookupTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Bitcode/BitstreamReader.h"
#include "llvm/Bitcode/BitstreamWriter.h"
#include "llvm/Bitcode/RecordLayout.h"
#include "llvm/Bitstream/BitstreamReader.h"
#include "llvm/Bitstream/BitstreamWriter.h"
#include "llvm/Support/DJB.h"
#include "llvm/Support/OnDiskHashTable.h"

Expand Down Expand Up @@ -1482,7 +1482,13 @@ SwiftLookupTableReader::create(clang::ModuleFileExtension *extension,
// Look for the base name -> entities table record.
SmallVector<uint64_t, 64> scratch;
auto cursor = stream;
auto next = cursor.advance();
llvm::Expected<llvm::BitstreamEntry> maybeNext = cursor.advance();
if (!maybeNext) {
// FIXME this drops the error on the floor.
consumeError(maybeNext.takeError());
return nullptr;
}
llvm::BitstreamEntry next = maybeNext.get();
std::unique_ptr<SerializedBaseNameToEntitiesTable> serializedTable;
std::unique_ptr<SerializedGlobalsAsMembersTable> globalsAsMembersTable;
ArrayRef<clang::serialization::DeclID> categories;
Expand All @@ -1495,14 +1501,27 @@ SwiftLookupTableReader::create(clang::ModuleFileExtension *extension,
// API notes format.
if (cursor.SkipBlock())
return nullptr;

next = cursor.advance();

maybeNext = cursor.advance();
if (!maybeNext) {
// FIXME this drops the error on the floor.
consumeError(maybeNext.takeError());
return nullptr;
}
next = maybeNext.get();
continue;
}

scratch.clear();
StringRef blobData;
unsigned kind = cursor.readRecord(next.ID, scratch, &blobData);
llvm::Expected<unsigned> maybeKind =
cursor.readRecord(next.ID, scratch, &blobData);
if (!maybeKind) {
// FIXME this drops the error on the floor.
consumeError(maybeNext.takeError());
return nullptr;
}
unsigned kind = maybeKind.get();
switch (kind) {
case BASE_NAME_TO_ENTITIES_RECORD_ID: {
// Already saw base name -> entities table.
Expand Down Expand Up @@ -1554,7 +1573,13 @@ SwiftLookupTableReader::create(clang::ModuleFileExtension *extension,
break;
}

next = cursor.advance();
maybeNext = cursor.advance();
if (!maybeNext) {
// FIXME this drops the error on the floor.
consumeError(maybeNext.takeError());
return nullptr;
}
next = maybeNext.get();
}

if (!serializedTable) return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion lib/Frontend/SerializedDiagnosticConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "llvm/Support/raw_ostream.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Bitcode/BitstreamWriter.h"
#include "llvm/Bitstream/BitstreamWriter.h"

// For constant values only.
#include "clang/Frontend/SerializedDiagnosticPrinter.h"
Expand Down
5 changes: 3 additions & 2 deletions lib/Serialization/BCReadingExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#ifndef SWIFT_SERIALIZATION_BCREADINGEXTRAS_H
#define SWIFT_SERIALIZATION_BCREADINGEXTRAS_H

#include "llvm/Bitcode/BitstreamReader.h"
#include "llvm/Bitstream/BitstreamReader.h"

namespace swift {
namespace serialization {
Expand All @@ -38,7 +38,8 @@ class BCOffsetRAII {

~BCOffsetRAII() {
if (Cursor)
Cursor->JumpToBit(Offset);
cantFail(Cursor->JumpToBit(Offset),
"BCOffsetRAII must be able to go back");
}
};

Expand Down
Loading