Skip to content

Fix Swift following bitstream reader API update #25845

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 11 commits into from
Jul 1, 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
3 changes: 2 additions & 1 deletion include/swift/Serialization/BCReadingExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions include/swift/Serialization/ModuleFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,15 @@ class ModuleFile
/// Emits one last diagnostic, logs the error, and then aborts for the stack
/// trace.
LLVM_ATTRIBUTE_NORETURN void fatal(llvm::Error error);
void fatalIfNotSuccess(llvm::Error error) {
if (error)
fatal(std::move(error));
}
template <typename T> T fatalIfUnexpected(llvm::Expected<T> expected) {
if (expected)
return std::move(expected.get());
fatal(expected.takeError());
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is new, it simplifies a good part of this patch.


ASTContext &getContext() const {
assert(FileContext && "no associated context yet");
Expand Down
35 changes: 30 additions & 5 deletions lib/ClangImporter/SwiftLookupTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1460,7 +1460,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 @@ -1473,14 +1479,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 @@ -1532,7 +1551,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
Loading