@@ -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)) {
@@ -2147,10 +2144,9 @@ Error MetadataLoader::MetadataLoaderImpl::parseMetadataStrings(
2147
2144
if (R.AtEndOfStream ())
2148
2145
return error (" Invalid record: metadata strings bad length" );
2149
2146
2150
- Expected<uint32_t > MaybeSize = R.ReadVBR (6 );
2151
- if (!MaybeSize)
2152
- return MaybeSize.takeError ();
2153
- uint32_t Size = MaybeSize.get ();
2147
+ uint32_t Size;
2148
+ if (Error E = R.ReadVBR (6 ).moveInto (Size))
2149
+ return E;
2154
2150
if (Strings.size () < Size)
2155
2151
return error (" Invalid record: metadata strings truncated chars" );
2156
2152
@@ -2187,10 +2183,9 @@ Error MetadataLoader::MetadataLoaderImpl::parseMetadataAttachment(
2187
2183
PlaceholderQueue Placeholders;
2188
2184
2189
2185
while (true ) {
2190
- Expected<BitstreamEntry> MaybeEntry = Stream.advanceSkippingSubblocks ();
2191
- if (!MaybeEntry)
2192
- return MaybeEntry.takeError ();
2193
- BitstreamEntry Entry = MaybeEntry.get ();
2186
+ BitstreamEntry Entry;
2187
+ if (Error E = Stream.advanceSkippingSubblocks ().moveInto (Entry))
2188
+ return E;
2194
2189
2195
2190
switch (Entry.Kind ) {
2196
2191
case BitstreamEntry::SubBlock: // Handled for us already.
@@ -2291,10 +2286,9 @@ Error MetadataLoader::MetadataLoaderImpl::parseMetadataKinds() {
2291
2286
2292
2287
// Read all the records.
2293
2288
while (true ) {
2294
- Expected<BitstreamEntry> MaybeEntry = Stream.advanceSkippingSubblocks ();
2295
- if (!MaybeEntry)
2296
- return MaybeEntry.takeError ();
2297
- BitstreamEntry Entry = MaybeEntry.get ();
2289
+ BitstreamEntry Entry;
2290
+ if (Error E = Stream.advanceSkippingSubblocks ().moveInto (Entry))
2291
+ return E;
2298
2292
2299
2293
switch (Entry.Kind ) {
2300
2294
case BitstreamEntry::SubBlock: // Handled for us already.
0 commit comments