@@ -163,6 +163,8 @@ const char UnsafeDeserializationError::ID = '\0';
163
163
void UnsafeDeserializationError::anchor () {}
164
164
const char ModularizationError::ID = ' \0 ' ;
165
165
void ModularizationError::anchor () {}
166
+ const char InvalidEnumValueError::ID = ' \0 ' ;
167
+ void InvalidEnumValueError::anchor () {}
166
168
167
169
// / Skips a single record in the bitstream.
168
170
// /
@@ -5295,8 +5297,9 @@ class DeclDeserializer {
5295
5297
return macro;
5296
5298
}
5297
5299
5298
- AvailableAttr *readAvailable_DECL_ATTR (SmallVectorImpl<uint64_t > &scratch,
5299
- StringRef blobData);
5300
+ Expected<AvailableAttr *>
5301
+ readAvailable_DECL_ATTR (SmallVectorImpl<uint64_t > &scratch,
5302
+ StringRef blobData);
5300
5303
};
5301
5304
}
5302
5305
@@ -5349,7 +5352,7 @@ ModuleFile::getDeclChecked(
5349
5352
return declOrOffset;
5350
5353
}
5351
5354
5352
- AvailableAttr *
5355
+ Expected< AvailableAttr *>
5353
5356
DeclDeserializer::readAvailable_DECL_ATTR (SmallVectorImpl<uint64_t > &scratch,
5354
5357
StringRef blobData) {
5355
5358
bool isImplicit;
@@ -5362,14 +5365,21 @@ DeclDeserializer::readAvailable_DECL_ATTR(SmallVectorImpl<uint64_t> &scratch,
5362
5365
DEF_VER_TUPLE_PIECES (Deprecated);
5363
5366
DEF_VER_TUPLE_PIECES (Obsoleted);
5364
5367
DeclID renameDeclID;
5365
- unsigned platform , messageSize, renameSize;
5368
+ unsigned rawPlatform , messageSize, renameSize;
5366
5369
5367
5370
// Decode the record, pulling the version tuple information.
5368
5371
serialization::decls_block::AvailableDeclAttrLayout::readRecord (
5369
5372
scratch, isImplicit, isUnavailable, isDeprecated, isNoAsync,
5370
- isPackageDescriptionVersionSpecific, isSPI, LIST_VER_TUPLE_PIECES (Introduced),
5371
- LIST_VER_TUPLE_PIECES (Deprecated), LIST_VER_TUPLE_PIECES (Obsoleted),
5372
- platform, renameDeclID, messageSize, renameSize);
5373
+ isPackageDescriptionVersionSpecific, isSPI,
5374
+ LIST_VER_TUPLE_PIECES (Introduced), LIST_VER_TUPLE_PIECES (Deprecated),
5375
+ LIST_VER_TUPLE_PIECES (Obsoleted), rawPlatform, renameDeclID, messageSize,
5376
+ renameSize);
5377
+
5378
+ auto maybePlatform = platformFromUnsigned (rawPlatform);
5379
+ if (!maybePlatform.has_value ())
5380
+ return llvm::make_error<InvalidEnumValueError>(rawPlatform, " PlatformKind" );
5381
+
5382
+ PlatformKind platform = maybePlatform.value ();
5373
5383
5374
5384
ValueDecl *renameDecl = nullptr ;
5375
5385
if (renameDeclID) {
@@ -5391,7 +5401,7 @@ DeclDeserializer::readAvailable_DECL_ATTR(SmallVectorImpl<uint64_t> &scratch,
5391
5401
platformAgnostic = PlatformAgnosticAvailabilityKind::Deprecated;
5392
5402
else if (isNoAsync)
5393
5403
platformAgnostic = PlatformAgnosticAvailabilityKind::NoAsync;
5394
- else if (((PlatformKind) platform) == PlatformKind::none &&
5404
+ else if (platform == PlatformKind::none &&
5395
5405
(!Introduced.empty () || !Deprecated.empty () || !Obsoleted.empty ()))
5396
5406
platformAgnostic =
5397
5407
isPackageDescriptionVersionSpecific
@@ -5402,9 +5412,9 @@ DeclDeserializer::readAvailable_DECL_ATTR(SmallVectorImpl<uint64_t> &scratch,
5402
5412
platformAgnostic = PlatformAgnosticAvailabilityKind::None;
5403
5413
5404
5414
auto attr = new (ctx) AvailableAttr (
5405
- SourceLoc (), SourceRange (), (PlatformKind) platform, message, rename,
5406
- renameDecl, Introduced, SourceRange (), Deprecated, SourceRange (),
5407
- Obsoleted, SourceRange (), platformAgnostic, isImplicit, isSPI);
5415
+ SourceLoc (), SourceRange (), platform, message, rename, renameDecl ,
5416
+ Introduced, SourceRange (), Deprecated, SourceRange (), Obsoleted ,
5417
+ SourceRange (), platformAgnostic, isImplicit, isSPI);
5408
5418
return attr;
5409
5419
}
5410
5420
@@ -5643,7 +5653,11 @@ llvm::Error DeclDeserializer::deserializeDeclCommon() {
5643
5653
}
5644
5654
5645
5655
case decls_block::Available_DECL_ATTR: {
5646
- Attr = readAvailable_DECL_ATTR (scratch, blobData);
5656
+ auto attrOrError = readAvailable_DECL_ATTR (scratch, blobData);
5657
+ if (!attrOrError)
5658
+ return MF.diagnoseFatal (attrOrError.takeError ());
5659
+
5660
+ Attr = attrOrError.get ();
5647
5661
break ;
5648
5662
}
5649
5663
@@ -5753,7 +5767,10 @@ llvm::Error DeclDeserializer::deserializeDeclCommon() {
5753
5767
}
5754
5768
5755
5769
auto attr = readAvailable_DECL_ATTR (scratch, blobData);
5756
- availabilityAttrs.push_back (attr);
5770
+ if (!attr)
5771
+ return MF.diagnoseFatal (attr.takeError ());
5772
+
5773
+ availabilityAttrs.push_back (attr.get ());
5757
5774
restoreOffset2.cancel ();
5758
5775
--numAvailabilityAttrs;
5759
5776
}
0 commit comments