mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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 50de105bf1)
Conflicts:
lib/Serialization/Deserialization.cpp
lib/Serialization/ModuleFile.cpp
tools/driver/modulewrap_main.cpp
This commit is contained in:
committed by
Francis Visoiu Mistrih
parent
9580510ae8
commit
e56e311a23
@@ -44,16 +44,31 @@ static_assert(IsTriviallyDestructible<SerializedASTFile>::value,
|
||||
|
||||
static bool checkModuleSignature(llvm::BitstreamCursor &cursor,
|
||||
ArrayRef<unsigned char> signature) {
|
||||
for (unsigned char byte : signature)
|
||||
if (cursor.AtEndOfStream() || cursor.Read(8) != byte)
|
||||
for (unsigned char byte : signature) {
|
||||
if (cursor.AtEndOfStream())
|
||||
return false;
|
||||
if (Expected<llvm::SimpleBitstreamCursor::word_t> maybeRead =
|
||||
cursor.Read(8)) {
|
||||
if (maybeRead.get() != byte)
|
||||
return false;
|
||||
} else {
|
||||
consumeError(maybeRead.takeError());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool enterTopLevelModuleBlock(llvm::BitstreamCursor &cursor,
|
||||
unsigned ID,
|
||||
bool shouldReadBlockInfo = true) {
|
||||
auto next = cursor.advance();
|
||||
Expected<llvm::BitstreamEntry> maybeNext = cursor.advance();
|
||||
if (!maybeNext) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(maybeNext.takeError());
|
||||
return false;
|
||||
}
|
||||
llvm::BitstreamEntry next = maybeNext.get();
|
||||
|
||||
if (next.Kind != llvm::BitstreamEntry::SubBlock)
|
||||
return false;
|
||||
@@ -72,7 +87,12 @@ static bool enterTopLevelModuleBlock(llvm::BitstreamCursor &cursor,
|
||||
if (next.ID != ID)
|
||||
return false;
|
||||
|
||||
cursor.EnterSubBlock(ID);
|
||||
if (llvm::Error Err = cursor.EnterSubBlock(ID)) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(std::move(Err));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -83,7 +103,13 @@ static bool readOptionsBlock(llvm::BitstreamCursor &cursor,
|
||||
SmallVectorImpl<uint64_t> &scratch,
|
||||
ExtendedValidationInfo &extendedInfo) {
|
||||
while (!cursor.AtEndOfStream()) {
|
||||
auto entry = cursor.advance();
|
||||
Expected<llvm::BitstreamEntry> maybeEntry = cursor.advance();
|
||||
if (!maybeEntry) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(maybeEntry.takeError());
|
||||
return false;
|
||||
}
|
||||
llvm::BitstreamEntry entry = maybeEntry.get();
|
||||
if (entry.Kind == llvm::BitstreamEntry::EndBlock)
|
||||
break;
|
||||
|
||||
@@ -100,7 +126,14 @@ static bool readOptionsBlock(llvm::BitstreamCursor &cursor,
|
||||
|
||||
scratch.clear();
|
||||
StringRef blobData;
|
||||
unsigned kind = cursor.readRecord(entry.ID, scratch, &blobData);
|
||||
Expected<unsigned> maybeKind =
|
||||
cursor.readRecord(entry.ID, scratch, &blobData);
|
||||
if (!maybeKind) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(maybeKind.takeError());
|
||||
return false;
|
||||
}
|
||||
unsigned kind = maybeKind.get();
|
||||
switch (kind) {
|
||||
case options_block::SDK_PATH:
|
||||
extendedInfo.setSDKPath(blobData);
|
||||
@@ -145,7 +178,14 @@ validateControlBlock(llvm::BitstreamCursor &cursor,
|
||||
bool versionSeen = false;
|
||||
|
||||
while (!cursor.AtEndOfStream()) {
|
||||
auto entry = cursor.advance();
|
||||
Expected<llvm::BitstreamEntry> maybeEntry = cursor.advance();
|
||||
if (!maybeEntry) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(maybeEntry.takeError());
|
||||
result.status = Status::Malformed;
|
||||
return result;
|
||||
}
|
||||
llvm::BitstreamEntry entry = maybeEntry.get();
|
||||
if (entry.Kind == llvm::BitstreamEntry::EndBlock)
|
||||
break;
|
||||
|
||||
@@ -156,7 +196,12 @@ validateControlBlock(llvm::BitstreamCursor &cursor,
|
||||
|
||||
if (entry.Kind == llvm::BitstreamEntry::SubBlock) {
|
||||
if (entry.ID == OPTIONS_BLOCK_ID && extendedInfo) {
|
||||
cursor.EnterSubBlock(OPTIONS_BLOCK_ID);
|
||||
if (llvm::Error Err = cursor.EnterSubBlock(OPTIONS_BLOCK_ID)) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(std::move(Err));
|
||||
result.status = Status::Malformed;
|
||||
return result;
|
||||
}
|
||||
if (!readOptionsBlock(cursor, scratch, *extendedInfo)) {
|
||||
result.status = Status::Malformed;
|
||||
return result;
|
||||
@@ -174,7 +219,15 @@ validateControlBlock(llvm::BitstreamCursor &cursor,
|
||||
|
||||
scratch.clear();
|
||||
StringRef blobData;
|
||||
unsigned kind = cursor.readRecord(entry.ID, scratch, &blobData);
|
||||
Expected<unsigned> maybeKind =
|
||||
cursor.readRecord(entry.ID, scratch, &blobData);
|
||||
if (!maybeKind) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(maybeKind.takeError());
|
||||
result.status = Status::Malformed;
|
||||
return result;
|
||||
}
|
||||
unsigned kind = maybeKind.get();
|
||||
switch (kind) {
|
||||
case control_block::METADATA: {
|
||||
if (versionSeen) {
|
||||
@@ -247,7 +300,13 @@ static bool validateInputBlock(
|
||||
SmallString<256> dependencyFullPathBuffer;
|
||||
|
||||
while (!cursor.AtEndOfStream()) {
|
||||
auto entry = cursor.advance();
|
||||
Expected<llvm::BitstreamEntry> maybeEntry = cursor.advance();
|
||||
if (!maybeEntry) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(maybeEntry.takeError());
|
||||
return true;
|
||||
}
|
||||
llvm::BitstreamEntry entry = maybeEntry.get();
|
||||
if (entry.Kind == llvm::BitstreamEntry::EndBlock)
|
||||
break;
|
||||
|
||||
@@ -256,7 +315,14 @@ static bool validateInputBlock(
|
||||
|
||||
scratch.clear();
|
||||
StringRef blobData;
|
||||
unsigned kind = cursor.readRecord(entry.ID, scratch, &blobData);
|
||||
Expected<unsigned> maybeKind =
|
||||
cursor.readRecord(entry.ID, scratch, &blobData);
|
||||
if (!maybeKind) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(maybeKind.takeError());
|
||||
return true;
|
||||
}
|
||||
unsigned kind = maybeKind.get();
|
||||
switch (kind) {
|
||||
case input_block::FILE_DEPENDENCY: {
|
||||
bool isHashBased = scratch[2] != 0;
|
||||
@@ -323,12 +389,25 @@ ValidationInfo serialization::validateSerializedAST(
|
||||
llvm::BitstreamEntry topLevelEntry;
|
||||
|
||||
while (!cursor.AtEndOfStream()) {
|
||||
topLevelEntry = cursor.advance(AF_DontPopBlockAtEnd);
|
||||
Expected<llvm::BitstreamEntry> maybeEntry =
|
||||
cursor.advance(AF_DontPopBlockAtEnd);
|
||||
if (!maybeEntry) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(maybeEntry.takeError());
|
||||
result.status = Status::Malformed;
|
||||
return result;
|
||||
}
|
||||
topLevelEntry = maybeEntry.get();
|
||||
if (topLevelEntry.Kind != llvm::BitstreamEntry::SubBlock)
|
||||
break;
|
||||
|
||||
if (topLevelEntry.ID == CONTROL_BLOCK_ID) {
|
||||
cursor.EnterSubBlock(CONTROL_BLOCK_ID);
|
||||
if (llvm::Error Err = cursor.EnterSubBlock(CONTROL_BLOCK_ID)) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(std::move(Err));
|
||||
result.status = Status::Malformed;
|
||||
return result;
|
||||
}
|
||||
result = validateControlBlock(cursor, scratch,
|
||||
{SWIFTMODULE_VERSION_MAJOR,
|
||||
SWIFTMODULE_VERSION_MINOR},
|
||||
@@ -338,7 +417,12 @@ ValidationInfo serialization::validateSerializedAST(
|
||||
} else if (dependencies &&
|
||||
result.status == Status::Valid &&
|
||||
topLevelEntry.ID == INPUT_BLOCK_ID) {
|
||||
cursor.EnterSubBlock(INPUT_BLOCK_ID);
|
||||
if (llvm::Error Err = cursor.EnterSubBlock(INPUT_BLOCK_ID)) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(std::move(Err));
|
||||
result.status = Status::Malformed;
|
||||
return result;
|
||||
}
|
||||
if (validateInputBlock(cursor, scratch, *dependencies)) {
|
||||
result.status = Status::Malformed;
|
||||
return result;
|
||||
@@ -827,13 +911,23 @@ ModuleFile::readObjCMethodTable(ArrayRef<uint64_t> fields, StringRef blobData) {
|
||||
}
|
||||
|
||||
bool ModuleFile::readIndexBlock(llvm::BitstreamCursor &cursor) {
|
||||
cursor.EnterSubBlock(INDEX_BLOCK_ID);
|
||||
if (llvm::Error Err = cursor.EnterSubBlock(INDEX_BLOCK_ID)) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(std::move(Err));
|
||||
return false;
|
||||
}
|
||||
|
||||
SmallVector<uint64_t, 4> scratch;
|
||||
StringRef blobData;
|
||||
|
||||
while (!cursor.AtEndOfStream()) {
|
||||
auto entry = cursor.advance();
|
||||
Expected<llvm::BitstreamEntry> maybeEntry = cursor.advance();
|
||||
if (!maybeEntry) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(maybeEntry.takeError());
|
||||
return false;
|
||||
}
|
||||
llvm::BitstreamEntry entry = maybeEntry.get();
|
||||
switch (entry.Kind) {
|
||||
case llvm::BitstreamEntry::EndBlock:
|
||||
return true;
|
||||
@@ -844,13 +938,25 @@ bool ModuleFile::readIndexBlock(llvm::BitstreamCursor &cursor) {
|
||||
case llvm::BitstreamEntry::SubBlock:
|
||||
if (entry.ID == DECL_MEMBER_TABLES_BLOCK_ID) {
|
||||
DeclMemberTablesCursor = cursor;
|
||||
DeclMemberTablesCursor.EnterSubBlock(DECL_MEMBER_TABLES_BLOCK_ID);
|
||||
if (llvm::Error Err = DeclMemberTablesCursor.EnterSubBlock(
|
||||
DECL_MEMBER_TABLES_BLOCK_ID)) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(std::move(Err));
|
||||
return false;
|
||||
}
|
||||
llvm::BitstreamEntry subentry;
|
||||
do {
|
||||
// Scan forward, to load the cursor with any abbrevs we'll need while
|
||||
// seeking inside this block later.
|
||||
subentry = DeclMemberTablesCursor.advance(
|
||||
llvm::BitstreamCursor::AF_DontPopBlockAtEnd);
|
||||
Expected<llvm::BitstreamEntry> maybeEntry =
|
||||
DeclMemberTablesCursor.advance(
|
||||
llvm::BitstreamCursor::AF_DontPopBlockAtEnd);
|
||||
if (!maybeEntry) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(maybeEntry.takeError());
|
||||
return false;
|
||||
}
|
||||
subentry = maybeEntry.get();
|
||||
} while (!DeclMemberTablesCursor.AtEndOfStream() &&
|
||||
subentry.Kind != llvm::BitstreamEntry::Record &&
|
||||
subentry.Kind != llvm::BitstreamEntry::EndBlock);
|
||||
@@ -862,7 +968,14 @@ bool ModuleFile::readIndexBlock(llvm::BitstreamCursor &cursor) {
|
||||
case llvm::BitstreamEntry::Record:
|
||||
scratch.clear();
|
||||
blobData = {};
|
||||
unsigned kind = cursor.readRecord(entry.ID, scratch, &blobData);
|
||||
Expected<unsigned> maybeKind =
|
||||
cursor.readRecord(entry.ID, scratch, &blobData);
|
||||
if (!maybeKind) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(maybeKind.takeError());
|
||||
return false;
|
||||
}
|
||||
unsigned kind = maybeKind.get();
|
||||
|
||||
switch (kind) {
|
||||
case index_block::DECL_OFFSETS:
|
||||
@@ -1044,13 +1157,23 @@ ModuleFile::readGroupTable(ArrayRef<uint64_t> Fields, StringRef BlobData) {
|
||||
}
|
||||
|
||||
bool ModuleFile::readCommentBlock(llvm::BitstreamCursor &cursor) {
|
||||
cursor.EnterSubBlock(COMMENT_BLOCK_ID);
|
||||
if (llvm::Error Err = cursor.EnterSubBlock(COMMENT_BLOCK_ID)) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(std::move(Err));
|
||||
return false;
|
||||
}
|
||||
|
||||
SmallVector<uint64_t, 4> scratch;
|
||||
StringRef blobData;
|
||||
|
||||
while (!cursor.AtEndOfStream()) {
|
||||
auto entry = cursor.advance();
|
||||
Expected<llvm::BitstreamEntry> maybeEntry = cursor.advance();
|
||||
if (!maybeEntry) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(maybeEntry.takeError());
|
||||
return false;
|
||||
}
|
||||
llvm::BitstreamEntry entry = maybeEntry.get();
|
||||
switch (entry.Kind) {
|
||||
case llvm::BitstreamEntry::EndBlock:
|
||||
return true;
|
||||
@@ -1066,7 +1189,14 @@ bool ModuleFile::readCommentBlock(llvm::BitstreamCursor &cursor) {
|
||||
|
||||
case llvm::BitstreamEntry::Record:
|
||||
scratch.clear();
|
||||
unsigned kind = cursor.readRecord(entry.ID, scratch, &blobData);
|
||||
Expected<unsigned> maybeKind =
|
||||
cursor.readRecord(entry.ID, scratch, &blobData);
|
||||
if (!maybeKind) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(maybeKind.takeError());
|
||||
return false;
|
||||
}
|
||||
unsigned kind = maybeKind.get();
|
||||
|
||||
switch (kind) {
|
||||
case comment_block::DECL_COMMENTS:
|
||||
@@ -1181,13 +1311,24 @@ bool ModuleFile::readModuleDocIfPresent() {
|
||||
ValidationInfo info;
|
||||
|
||||
while (!docCursor.AtEndOfStream()) {
|
||||
topLevelEntry = docCursor.advance(AF_DontPopBlockAtEnd);
|
||||
Expected<llvm::BitstreamEntry> maybeEntry =
|
||||
docCursor.advance(AF_DontPopBlockAtEnd);
|
||||
if (!maybeEntry) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(maybeEntry.takeError());
|
||||
return false;
|
||||
}
|
||||
topLevelEntry = maybeEntry.get();
|
||||
if (topLevelEntry.Kind != llvm::BitstreamEntry::SubBlock)
|
||||
break;
|
||||
|
||||
switch (topLevelEntry.ID) {
|
||||
case CONTROL_BLOCK_ID: {
|
||||
docCursor.EnterSubBlock(CONTROL_BLOCK_ID);
|
||||
if (llvm::Error Err = docCursor.EnterSubBlock(CONTROL_BLOCK_ID)) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(std::move(Err));
|
||||
return false;
|
||||
}
|
||||
|
||||
info = validateControlBlock(docCursor, scratch,
|
||||
{SWIFTDOC_VERSION_MAJOR,
|
||||
@@ -1270,14 +1411,21 @@ ModuleFile::readDeclUSRsTable(ArrayRef<uint64_t> fields, StringRef blobData) {
|
||||
}
|
||||
|
||||
bool ModuleFile::readDeclLocsBlock(llvm::BitstreamCursor &cursor) {
|
||||
cursor.EnterSubBlock(DECL_LOCS_BLOCK_ID);
|
||||
if (llvm::Error Err = cursor.EnterSubBlock(CONTROL_BLOCK_ID)) {
|
||||
consumeError(std::move(Err));
|
||||
return false;
|
||||
}
|
||||
|
||||
SmallVector<uint64_t, 4> scratch;
|
||||
StringRef blobData;
|
||||
|
||||
while (!cursor.AtEndOfStream()) {
|
||||
auto entry = cursor.advance();
|
||||
switch (entry.Kind) {
|
||||
Expected<llvm::BitstreamEntry> entry = cursor.advance();
|
||||
if (!entry) {
|
||||
consumeError(entry.takeError());
|
||||
return false;
|
||||
}
|
||||
switch (entry->Kind) {
|
||||
case llvm::BitstreamEntry::EndBlock:
|
||||
return true;
|
||||
|
||||
@@ -1292,9 +1440,13 @@ bool ModuleFile::readDeclLocsBlock(llvm::BitstreamCursor &cursor) {
|
||||
|
||||
case llvm::BitstreamEntry::Record:
|
||||
scratch.clear();
|
||||
unsigned kind = cursor.readRecord(entry.ID, scratch, &blobData);
|
||||
|
||||
switch (kind) {
|
||||
Expected<unsigned> kind =
|
||||
cursor.readRecord(entry->ID, scratch, &blobData);
|
||||
if (!kind) {
|
||||
consumeError(kind.takeError());
|
||||
return false;
|
||||
}
|
||||
switch (*kind) {
|
||||
case decl_locs_block::BASIC_DECL_LOCS:
|
||||
BasicDeclLocsData = blobData;
|
||||
break;
|
||||
@@ -1326,20 +1478,28 @@ bool ModuleFile::readModuleSourceInfoIfPresent() {
|
||||
}
|
||||
|
||||
SmallVector<uint64_t, 64> scratch;
|
||||
llvm::BitstreamEntry topLevelEntry;
|
||||
|
||||
bool hasValidControlBlock = false;
|
||||
ValidationInfo info;
|
||||
unsigned kind = llvm::BitstreamEntry::Error;
|
||||
|
||||
while (!infoCursor.AtEndOfStream()) {
|
||||
topLevelEntry = infoCursor.advance(AF_DontPopBlockAtEnd);
|
||||
if (topLevelEntry.Kind != llvm::BitstreamEntry::SubBlock)
|
||||
Expected<llvm::BitstreamEntry> topLevelEntry =
|
||||
infoCursor.advance(AF_DontPopBlockAtEnd);
|
||||
if (!topLevelEntry) {
|
||||
consumeError(topLevelEntry.takeError());
|
||||
return false;
|
||||
}
|
||||
kind = topLevelEntry->Kind;
|
||||
if (kind != llvm::BitstreamEntry::SubBlock)
|
||||
break;
|
||||
|
||||
switch (topLevelEntry.ID) {
|
||||
switch (topLevelEntry->ID) {
|
||||
case CONTROL_BLOCK_ID: {
|
||||
infoCursor.EnterSubBlock(CONTROL_BLOCK_ID);
|
||||
|
||||
if (llvm::Error Err = infoCursor.EnterSubBlock(CONTROL_BLOCK_ID)) {
|
||||
consumeError(std::move(Err));
|
||||
return false;
|
||||
}
|
||||
info = validateControlBlock(infoCursor, scratch,
|
||||
{SWIFTSOURCEINFO_VERSION_MAJOR,
|
||||
SWIFTSOURCEINFO_VERSION_MINOR},
|
||||
@@ -1368,7 +1528,7 @@ bool ModuleFile::readModuleSourceInfoIfPresent() {
|
||||
}
|
||||
}
|
||||
|
||||
if (topLevelEntry.Kind != llvm::BitstreamEntry::EndBlock)
|
||||
if (kind != llvm::BitstreamEntry::EndBlock)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -1405,13 +1565,26 @@ ModuleFile::ModuleFile(
|
||||
llvm::BitstreamEntry topLevelEntry;
|
||||
|
||||
while (!cursor.AtEndOfStream()) {
|
||||
topLevelEntry = cursor.advance(AF_DontPopBlockAtEnd);
|
||||
Expected<llvm::BitstreamEntry> maybeEntry =
|
||||
cursor.advance(AF_DontPopBlockAtEnd);
|
||||
if (!maybeEntry) {
|
||||
// FIXME this drops the error diagnostic on the floor.
|
||||
consumeError(maybeEntry.takeError());
|
||||
info.status = error(Status::Malformed);
|
||||
return;
|
||||
}
|
||||
topLevelEntry = maybeEntry.get();
|
||||
if (topLevelEntry.Kind != llvm::BitstreamEntry::SubBlock)
|
||||
break;
|
||||
|
||||
switch (topLevelEntry.ID) {
|
||||
case CONTROL_BLOCK_ID: {
|
||||
cursor.EnterSubBlock(CONTROL_BLOCK_ID);
|
||||
if (llvm::Error Err = cursor.EnterSubBlock(CONTROL_BLOCK_ID)) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(std::move(Err));
|
||||
info.status = error(Status::Malformed);
|
||||
return;
|
||||
}
|
||||
|
||||
info = validateControlBlock(cursor, scratch,
|
||||
{SWIFTMODULE_VERSION_MAJOR,
|
||||
@@ -1436,13 +1609,33 @@ ModuleFile::ModuleFile(
|
||||
return;
|
||||
}
|
||||
|
||||
cursor.EnterSubBlock(INPUT_BLOCK_ID);
|
||||
if (llvm::Error Err = cursor.EnterSubBlock(INPUT_BLOCK_ID)) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(std::move(Err));
|
||||
info.status = error(Status::Malformed);
|
||||
return;
|
||||
}
|
||||
|
||||
auto next = cursor.advance();
|
||||
Expected<llvm::BitstreamEntry> maybeNext = cursor.advance();
|
||||
if (!maybeNext) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(maybeNext.takeError());
|
||||
info.status = error(Status::Malformed);
|
||||
return;
|
||||
}
|
||||
llvm::BitstreamEntry next = maybeNext.get();
|
||||
while (next.Kind == llvm::BitstreamEntry::Record) {
|
||||
scratch.clear();
|
||||
StringRef blobData;
|
||||
unsigned kind = cursor.readRecord(next.ID, scratch, &blobData);
|
||||
Expected<unsigned> maybeKind =
|
||||
cursor.readRecord(next.ID, scratch, &blobData);
|
||||
if (!maybeKind) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(maybeKind.takeError());
|
||||
info.status = error(Status::Malformed);
|
||||
return;
|
||||
}
|
||||
unsigned kind = maybeKind.get();
|
||||
switch (kind) {
|
||||
case input_block::IMPORTED_MODULE: {
|
||||
unsigned rawImportControl;
|
||||
@@ -1504,7 +1697,14 @@ ModuleFile::ModuleFile(
|
||||
break;
|
||||
}
|
||||
|
||||
next = cursor.advance();
|
||||
maybeNext = cursor.advance();
|
||||
if (!maybeNext) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(maybeNext.takeError());
|
||||
info.status = error(Status::Malformed);
|
||||
return;
|
||||
}
|
||||
next = maybeNext.get();
|
||||
}
|
||||
|
||||
if (next.Kind != llvm::BitstreamEntry::EndBlock)
|
||||
@@ -1522,8 +1722,22 @@ ModuleFile::ModuleFile(
|
||||
// The decls-and-types block is lazily loaded. Save the cursor and load
|
||||
// any abbrev records at the start of the block.
|
||||
DeclTypeCursor = cursor;
|
||||
DeclTypeCursor.EnterSubBlock(DECLS_AND_TYPES_BLOCK_ID);
|
||||
if (DeclTypeCursor.advance().Kind == llvm::BitstreamEntry::Error)
|
||||
if (llvm::Error Err =
|
||||
DeclTypeCursor.EnterSubBlock(DECLS_AND_TYPES_BLOCK_ID)) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(std::move(Err));
|
||||
info.status = error(Status::Malformed);
|
||||
return;
|
||||
}
|
||||
|
||||
Expected<llvm::BitstreamEntry> maybeCursor = DeclTypeCursor.advance();
|
||||
if (!maybeCursor) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(maybeCursor.takeError());
|
||||
info.status = error(Status::Malformed);
|
||||
return;
|
||||
}
|
||||
if (maybeCursor.get().Kind == llvm::BitstreamEntry::Error)
|
||||
info.status = error(Status::Malformed);
|
||||
|
||||
// With the main cursor, skip over the block and continue.
|
||||
@@ -1540,13 +1754,34 @@ ModuleFile::ModuleFile(
|
||||
return;
|
||||
}
|
||||
|
||||
cursor.EnterSubBlock(IDENTIFIER_DATA_BLOCK_ID);
|
||||
if (llvm::Error Err = cursor.EnterSubBlock(IDENTIFIER_DATA_BLOCK_ID)) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(std::move(Err));
|
||||
info.status = error(Status::Malformed);
|
||||
return;
|
||||
}
|
||||
|
||||
auto next = cursor.advanceSkippingSubblocks();
|
||||
Expected<llvm::BitstreamEntry> maybeNext =
|
||||
cursor.advanceSkippingSubblocks();
|
||||
if (!maybeNext) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(maybeNext.takeError());
|
||||
info.status = error(Status::Malformed);
|
||||
return;
|
||||
}
|
||||
llvm::BitstreamEntry next = maybeNext.get();
|
||||
while (next.Kind == llvm::BitstreamEntry::Record) {
|
||||
scratch.clear();
|
||||
StringRef blobData;
|
||||
unsigned kind = cursor.readRecord(next.ID, scratch, &blobData);
|
||||
Expected<unsigned> maybeKind =
|
||||
cursor.readRecord(next.ID, scratch, &blobData);
|
||||
if (!maybeKind) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(maybeKind.takeError());
|
||||
info.status = error(Status::Malformed);
|
||||
return;
|
||||
}
|
||||
unsigned kind = maybeKind.get();
|
||||
|
||||
switch (kind) {
|
||||
case identifier_block::IDENTIFIER_DATA:
|
||||
@@ -1559,7 +1794,14 @@ ModuleFile::ModuleFile(
|
||||
break;
|
||||
}
|
||||
|
||||
next = cursor.advanceSkippingSubblocks();
|
||||
maybeNext = cursor.advanceSkippingSubblocks();
|
||||
if (!maybeNext) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(maybeNext.takeError());
|
||||
info.status = error(Status::Malformed);
|
||||
return;
|
||||
}
|
||||
next = maybeNext.get();
|
||||
}
|
||||
|
||||
if (next.Kind != llvm::BitstreamEntry::EndBlock) {
|
||||
@@ -1581,7 +1823,12 @@ ModuleFile::ModuleFile(
|
||||
case SIL_INDEX_BLOCK_ID: {
|
||||
// Save the cursor.
|
||||
SILIndexCursor = cursor;
|
||||
SILIndexCursor.EnterSubBlock(SIL_INDEX_BLOCK_ID);
|
||||
if (llvm::Error Err = SILIndexCursor.EnterSubBlock(SIL_INDEX_BLOCK_ID)) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(std::move(Err));
|
||||
info.status = error(Status::Malformed);
|
||||
return;
|
||||
}
|
||||
|
||||
// With the main cursor, skip over the block and continue.
|
||||
if (cursor.SkipBlock()) {
|
||||
@@ -1594,7 +1841,12 @@ ModuleFile::ModuleFile(
|
||||
case SIL_BLOCK_ID: {
|
||||
// Save the cursor.
|
||||
SILCursor = cursor;
|
||||
SILCursor.EnterSubBlock(SIL_BLOCK_ID);
|
||||
if (llvm::Error Err = SILCursor.EnterSubBlock(SIL_BLOCK_ID)) {
|
||||
// FIXME this drops the error on the floor.
|
||||
consumeError(std::move(Err));
|
||||
info.status = error(Status::Malformed);
|
||||
return;
|
||||
}
|
||||
|
||||
// With the main cursor, skip over the block and continue.
|
||||
if (cursor.SkipBlock()) {
|
||||
@@ -2138,16 +2390,17 @@ ModuleFile::loadNamedMembers(const IterableDeclContext *IDC, DeclBaseName N,
|
||||
DeclMembersTables[subTableOffset];
|
||||
if (!subTable) {
|
||||
BCOffsetRAII restoreOffset(DeclMemberTablesCursor);
|
||||
DeclMemberTablesCursor.JumpToBit(subTableOffset);
|
||||
auto entry = DeclMemberTablesCursor.advance();
|
||||
fatalIfNotSuccess(DeclMemberTablesCursor.JumpToBit(subTableOffset));
|
||||
llvm::BitstreamEntry entry =
|
||||
fatalIfUnexpected(DeclMemberTablesCursor.advance());
|
||||
if (entry.Kind != llvm::BitstreamEntry::Record) {
|
||||
fatal();
|
||||
return None;
|
||||
}
|
||||
SmallVector<uint64_t, 64> scratch;
|
||||
StringRef blobData;
|
||||
unsigned kind = DeclMemberTablesCursor.readRecord(entry.ID, scratch,
|
||||
&blobData);
|
||||
unsigned kind = fatalIfUnexpected(
|
||||
DeclMemberTablesCursor.readRecord(entry.ID, scratch, &blobData));
|
||||
assert(kind == decl_member_tables_block::DECL_MEMBERS);
|
||||
(void)kind;
|
||||
subTable = readDeclMembersTable(scratch, blobData);
|
||||
@@ -2166,7 +2419,7 @@ ModuleFile::loadNamedMembers(const IterableDeclContext *IDC, DeclBaseName N,
|
||||
} else {
|
||||
if (!getContext().LangOpts.EnableDeserializationRecovery)
|
||||
fatal(mem.takeError());
|
||||
llvm::consumeError(mem.takeError());
|
||||
consumeError(mem.takeError());
|
||||
|
||||
// Treat this as a cache-miss to the caller and let them attempt
|
||||
// to refill through the normal loadAllMembers() path.
|
||||
@@ -2293,7 +2546,7 @@ void ModuleFile::getTopLevelDecls(SmallVectorImpl<Decl *> &results) {
|
||||
if (!declOrError) {
|
||||
if (!getContext().LangOpts.EnableDeserializationRecovery)
|
||||
fatal(declOrError.takeError());
|
||||
llvm::consumeError(declOrError.takeError());
|
||||
consumeError(declOrError.takeError());
|
||||
continue;
|
||||
}
|
||||
results.push_back(declOrError.get());
|
||||
|
||||
Reference in New Issue
Block a user