@@ -697,11 +697,12 @@ MetadataLoader::MetadataLoaderImpl::lazyLoadModuleMetadataBlock() {
697
697
// Get the abbrevs, and preload record positions to make them lazy-loadable.
698
698
while (true ) {
699
699
uint64_t SavedPos = IndexCursor.GetCurrentBitNo ();
700
- Expected<BitstreamEntry> MaybeEntry = IndexCursor.advanceSkippingSubblocks (
701
- BitstreamCursor::AF_DontPopBlockAtEnd);
702
- if (!MaybeEntry)
703
- return MaybeEntry.takeError ();
704
- BitstreamEntry Entry = MaybeEntry.get ();
700
+ BitstreamEntry Entry;
701
+ if (Error E =
702
+ IndexCursor
703
+ .advanceSkippingSubblocks (BitstreamCursor::AF_DontPopBlockAtEnd)
704
+ .moveInto (Entry))
705
+ return std::move (E);
705
706
706
707
switch (Entry.Kind ) {
707
708
case BitstreamEntry::SubBlock: // Handled for us already.
@@ -714,10 +715,9 @@ MetadataLoader::MetadataLoaderImpl::lazyLoadModuleMetadataBlock() {
714
715
// The interesting case.
715
716
++NumMDRecordLoaded;
716
717
uint64_t CurrentPos = IndexCursor.GetCurrentBitNo ();
717
- Expected<unsigned > MaybeCode = IndexCursor.skipRecord (Entry.ID );
718
- if (!MaybeCode)
719
- return MaybeCode.takeError ();
720
- unsigned Code = MaybeCode.get ();
718
+ unsigned Code;
719
+ if (Error E = IndexCursor.skipRecord (Entry.ID ).moveInto (Code))
720
+ return std::move (E);
721
721
switch (Code) {
722
722
case bitc::METADATA_STRINGS: {
723
723
// Rewind and parse the strings.
@@ -904,11 +904,12 @@ Expected<bool> MetadataLoader::MetadataLoaderImpl::loadGlobalDeclAttachments() {
904
904
if (Error Err = TempCursor.JumpToBit (GlobalDeclAttachmentPos))
905
905
return std::move (Err);
906
906
while (true ) {
907
- Expected<BitstreamEntry> MaybeEntry = TempCursor.advanceSkippingSubblocks (
908
- BitstreamCursor::AF_DontPopBlockAtEnd);
909
- if (!MaybeEntry)
910
- return MaybeEntry.takeError ();
911
- BitstreamEntry Entry = MaybeEntry.get ();
907
+ BitstreamEntry Entry;
908
+ if (Error E =
909
+ TempCursor
910
+ .advanceSkippingSubblocks (BitstreamCursor::AF_DontPopBlockAtEnd)
911
+ .moveInto (Entry))
912
+ return std::move (E);
912
913
913
914
switch (Entry.Kind ) {
914
915
case BitstreamEntry::SubBlock: // Handled for us already.
@@ -1024,10 +1025,9 @@ Error MetadataLoader::MetadataLoaderImpl::parseMetadata(bool ModuleLevel) {
1024
1025
1025
1026
// Read all the records.
1026
1027
while (true ) {
1027
- Expected<BitstreamEntry> MaybeEntry = Stream.advanceSkippingSubblocks ();
1028
- if (!MaybeEntry)
1029
- return MaybeEntry.takeError ();
1030
- BitstreamEntry Entry = MaybeEntry.get ();
1028
+ BitstreamEntry Entry;
1029
+ if (Error E = Stream.advanceSkippingSubblocks ().moveInto (Entry))
1030
+ return E;
1031
1031
1032
1032
switch (Entry.Kind ) {
1033
1033
case BitstreamEntry::SubBlock: // Handled for us already.
@@ -1081,12 +1081,11 @@ void MetadataLoader::MetadataLoaderImpl::lazyLoadOneMetadata(
1081
1081
GlobalMetadataBitPosIndex[ID - MDStringRef.size ()]))
1082
1082
report_fatal_error (" lazyLoadOneMetadata failed jumping: " +
1083
1083
Twine (toString (std::move (Err))));
1084
- Expected< BitstreamEntry> MaybeEntry = IndexCursor. advanceSkippingSubblocks () ;
1085
- if (!MaybeEntry )
1084
+ BitstreamEntry Entry ;
1085
+ if (Error E = IndexCursor. advanceSkippingSubblocks (). moveInto (Entry) )
1086
1086
// FIXME this drops the error on the floor.
1087
1087
report_fatal_error (" lazyLoadOneMetadata failed advanceSkippingSubblocks: " +
1088
- Twine (toString (MaybeEntry.takeError ())));
1089
- BitstreamEntry Entry = MaybeEntry.get ();
1088
+ Twine (toString (std::move (E))));
1090
1089
++NumMDRecordLoaded;
1091
1090
if (Expected<unsigned > MaybeCode =
1092
1091
IndexCursor.readRecord (Entry.ID , Record, &Blob)) {
@@ -1193,10 +1192,8 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
1193
1192
// Read name of the named metadata.
1194
1193
SmallString<8 > Name (Record.begin (), Record.end ());
1195
1194
Record.clear ();
1196
- Expected<unsigned > MaybeCode = Stream.ReadCode ();
1197
- if (!MaybeCode)
1198
- return MaybeCode.takeError ();
1199
- Code = MaybeCode.get ();
1195
+ if (Error E = Stream.ReadCode ().moveInto (Code))
1196
+ return E;
1200
1197
1201
1198
++NumMDRecordLoaded;
1202
1199
if (Expected<unsigned > MaybeNextBitCode = Stream.readRecord (Code, Record)) {
@@ -2151,10 +2148,9 @@ Error MetadataLoader::MetadataLoaderImpl::parseMetadataStrings(
2151
2148
if (R.AtEndOfStream ())
2152
2149
return error (" Invalid record: metadata strings bad length" );
2153
2150
2154
- Expected<uint32_t > MaybeSize = R.ReadVBR (6 );
2155
- if (!MaybeSize)
2156
- return MaybeSize.takeError ();
2157
- uint32_t Size = MaybeSize.get ();
2151
+ uint32_t Size;
2152
+ if (Error E = R.ReadVBR (6 ).moveInto (Size))
2153
+ return E;
2158
2154
if (Strings.size () < Size)
2159
2155
return error (" Invalid record: metadata strings truncated chars" );
2160
2156
@@ -2191,10 +2187,9 @@ Error MetadataLoader::MetadataLoaderImpl::parseMetadataAttachment(
2191
2187
PlaceholderQueue Placeholders;
2192
2188
2193
2189
while (true ) {
2194
- Expected<BitstreamEntry> MaybeEntry = Stream.advanceSkippingSubblocks ();
2195
- if (!MaybeEntry)
2196
- return MaybeEntry.takeError ();
2197
- BitstreamEntry Entry = MaybeEntry.get ();
2190
+ BitstreamEntry Entry;
2191
+ if (Error E = Stream.advanceSkippingSubblocks ().moveInto (Entry))
2192
+ return E;
2198
2193
2199
2194
switch (Entry.Kind ) {
2200
2195
case BitstreamEntry::SubBlock: // Handled for us already.
@@ -2295,10 +2290,9 @@ Error MetadataLoader::MetadataLoaderImpl::parseMetadataKinds() {
2295
2290
2296
2291
// Read all the records.
2297
2292
while (true ) {
2298
- Expected<BitstreamEntry> MaybeEntry = Stream.advanceSkippingSubblocks ();
2299
- if (!MaybeEntry)
2300
- return MaybeEntry.takeError ();
2301
- BitstreamEntry Entry = MaybeEntry.get ();
2293
+ BitstreamEntry Entry;
2294
+ if (Error E = Stream.advanceSkippingSubblocks ().moveInto (Entry))
2295
+ return E;
2302
2296
2303
2297
switch (Entry.Kind ) {
2304
2298
case BitstreamEntry::SubBlock: // Handled for us already.
0 commit comments