Skip to content

Commit e56e311

Browse files
jfbastienfrancisvm
authored andcommitted
Fix Swift following bitstream reader API update (#25845)
* Fix Swift following bitstream reader API update Upstream change in rL364464 broke downstream Swift. (cherry picked from commit 50de105) Conflicts: lib/Serialization/Deserialization.cpp lib/Serialization/ModuleFile.cpp tools/driver/modulewrap_main.cpp
1 parent 9580510 commit e56e311

File tree

6 files changed

+632
-190
lines changed

6 files changed

+632
-190
lines changed

lib/ClangImporter/SwiftLookupTable.cpp

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,13 @@ SwiftLookupTableReader::create(clang::ModuleFileExtension *extension,
14821482
// Look for the base name -> entities table record.
14831483
SmallVector<uint64_t, 64> scratch;
14841484
auto cursor = stream;
1485-
auto next = cursor.advance();
1485+
llvm::Expected<llvm::BitstreamEntry> maybeNext = cursor.advance();
1486+
if (!maybeNext) {
1487+
// FIXME this drops the error on the floor.
1488+
consumeError(maybeNext.takeError());
1489+
return nullptr;
1490+
}
1491+
llvm::BitstreamEntry next = maybeNext.get();
14861492
std::unique_ptr<SerializedBaseNameToEntitiesTable> serializedTable;
14871493
std::unique_ptr<SerializedGlobalsAsMembersTable> globalsAsMembersTable;
14881494
ArrayRef<clang::serialization::DeclID> categories;
@@ -1495,14 +1501,27 @@ SwiftLookupTableReader::create(clang::ModuleFileExtension *extension,
14951501
// API notes format.
14961502
if (cursor.SkipBlock())
14971503
return nullptr;
1498-
1499-
next = cursor.advance();
1504+
1505+
maybeNext = cursor.advance();
1506+
if (!maybeNext) {
1507+
// FIXME this drops the error on the floor.
1508+
consumeError(maybeNext.takeError());
1509+
return nullptr;
1510+
}
1511+
next = maybeNext.get();
15001512
continue;
15011513
}
15021514

15031515
scratch.clear();
15041516
StringRef blobData;
1505-
unsigned kind = cursor.readRecord(next.ID, scratch, &blobData);
1517+
llvm::Expected<unsigned> maybeKind =
1518+
cursor.readRecord(next.ID, scratch, &blobData);
1519+
if (!maybeKind) {
1520+
// FIXME this drops the error on the floor.
1521+
consumeError(maybeNext.takeError());
1522+
return nullptr;
1523+
}
1524+
unsigned kind = maybeKind.get();
15061525
switch (kind) {
15071526
case BASE_NAME_TO_ENTITIES_RECORD_ID: {
15081527
// Already saw base name -> entities table.
@@ -1554,7 +1573,13 @@ SwiftLookupTableReader::create(clang::ModuleFileExtension *extension,
15541573
break;
15551574
}
15561575

1557-
next = cursor.advance();
1576+
maybeNext = cursor.advance();
1577+
if (!maybeNext) {
1578+
// FIXME this drops the error on the floor.
1579+
consumeError(maybeNext.takeError());
1580+
return nullptr;
1581+
}
1582+
next = maybeNext.get();
15581583
}
15591584

15601585
if (!serializedTable) return nullptr;

lib/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

0 commit comments

Comments
 (0)