Skip to content

Commit 50de105

Browse files
authored
Fix Swift following bitstream reader API update (#25845)
* Fix Swift following bitstream reader API update Upstream change in rL364464 broke downstream Swift.
1 parent d57e0cc commit 50de105

File tree

7 files changed

+622
-185
lines changed

7 files changed

+622
-185
lines changed

include/swift/Serialization/BCReadingExtras.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ class BCOffsetRAII {
3838

3939
~BCOffsetRAII() {
4040
if (Cursor)
41-
Cursor->JumpToBit(Offset);
41+
cantFail(Cursor->JumpToBit(Offset),
42+
"BCOffsetRAII must be able to go back");
4243
}
4344
};
4445

include/swift/Serialization/ModuleFile.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,15 @@ class ModuleFile
502502
/// Emits one last diagnostic, logs the error, and then aborts for the stack
503503
/// trace.
504504
LLVM_ATTRIBUTE_NORETURN void fatal(llvm::Error error);
505+
void fatalIfNotSuccess(llvm::Error error) {
506+
if (error)
507+
fatal(std::move(error));
508+
}
509+
template <typename T> T fatalIfUnexpected(llvm::Expected<T> expected) {
510+
if (expected)
511+
return std::move(expected.get());
512+
fatal(expected.takeError());
513+
}
505514

506515
ASTContext &getContext() const {
507516
assert(FileContext && "no associated context yet");

lib/ClangImporter/SwiftLookupTable.cpp

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,7 +1460,13 @@ SwiftLookupTableReader::create(clang::ModuleFileExtension *extension,
14601460
// Look for the base name -> entities table record.
14611461
SmallVector<uint64_t, 64> scratch;
14621462
auto cursor = stream;
1463-
auto next = cursor.advance();
1463+
llvm::Expected<llvm::BitstreamEntry> maybeNext = cursor.advance();
1464+
if (!maybeNext) {
1465+
// FIXME this drops the error on the floor.
1466+
consumeError(maybeNext.takeError());
1467+
return nullptr;
1468+
}
1469+
llvm::BitstreamEntry next = maybeNext.get();
14641470
std::unique_ptr<SerializedBaseNameToEntitiesTable> serializedTable;
14651471
std::unique_ptr<SerializedGlobalsAsMembersTable> globalsAsMembersTable;
14661472
ArrayRef<clang::serialization::DeclID> categories;
@@ -1473,14 +1479,27 @@ SwiftLookupTableReader::create(clang::ModuleFileExtension *extension,
14731479
// API notes format.
14741480
if (cursor.SkipBlock())
14751481
return nullptr;
1476-
1477-
next = cursor.advance();
1482+
1483+
maybeNext = cursor.advance();
1484+
if (!maybeNext) {
1485+
// FIXME this drops the error on the floor.
1486+
consumeError(maybeNext.takeError());
1487+
return nullptr;
1488+
}
1489+
next = maybeNext.get();
14781490
continue;
14791491
}
14801492

14811493
scratch.clear();
14821494
StringRef blobData;
1483-
unsigned kind = cursor.readRecord(next.ID, scratch, &blobData);
1495+
llvm::Expected<unsigned> maybeKind =
1496+
cursor.readRecord(next.ID, scratch, &blobData);
1497+
if (!maybeKind) {
1498+
// FIXME this drops the error on the floor.
1499+
consumeError(maybeNext.takeError());
1500+
return nullptr;
1501+
}
1502+
unsigned kind = maybeKind.get();
14841503
switch (kind) {
14851504
case BASE_NAME_TO_ENTITIES_RECORD_ID: {
14861505
// Already saw base name -> entities table.
@@ -1532,7 +1551,13 @@ SwiftLookupTableReader::create(clang::ModuleFileExtension *extension,
15321551
break;
15331552
}
15341553

1535-
next = cursor.advance();
1554+
maybeNext = cursor.advance();
1555+
if (!maybeNext) {
1556+
// FIXME this drops the error on the floor.
1557+
consumeError(maybeNext.takeError());
1558+
return nullptr;
1559+
}
1560+
next = maybeNext.get();
15361561
}
15371562

15381563
if (!serializedTable) return nullptr;

0 commit comments

Comments
 (0)