@@ -163,6 +163,8 @@ const char UnsafeDeserializationError::ID = '\0';
163163void UnsafeDeserializationError::anchor () {}
164164const char ModularizationError::ID = ' \0 ' ;
165165void ModularizationError::anchor () {}
166+ const char InvalidEnumValueError::ID = ' \0 ' ;
167+ void InvalidEnumValueError::anchor () {}
166168
167169// / Skips a single record in the bitstream.
168170// /
@@ -5295,8 +5297,9 @@ class DeclDeserializer {
52955297 return macro;
52965298 }
52975299
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);
53005303};
53015304}
53025305
@@ -5349,7 +5352,7 @@ ModuleFile::getDeclChecked(
53495352 return declOrOffset;
53505353}
53515354
5352- AvailableAttr *
5355+ Expected< AvailableAttr *>
53535356DeclDeserializer::readAvailable_DECL_ATTR (SmallVectorImpl<uint64_t > &scratch,
53545357 StringRef blobData) {
53555358 bool isImplicit;
@@ -5362,14 +5365,21 @@ DeclDeserializer::readAvailable_DECL_ATTR(SmallVectorImpl<uint64_t> &scratch,
53625365 DEF_VER_TUPLE_PIECES (Deprecated);
53635366 DEF_VER_TUPLE_PIECES (Obsoleted);
53645367 DeclID renameDeclID;
5365- unsigned platform , messageSize, renameSize;
5368+ unsigned rawPlatform , messageSize, renameSize;
53665369
53675370 // Decode the record, pulling the version tuple information.
53685371 serialization::decls_block::AvailableDeclAttrLayout::readRecord (
53695372 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 ();
53735383
53745384 ValueDecl *renameDecl = nullptr ;
53755385 if (renameDeclID) {
@@ -5391,7 +5401,7 @@ DeclDeserializer::readAvailable_DECL_ATTR(SmallVectorImpl<uint64_t> &scratch,
53915401 platformAgnostic = PlatformAgnosticAvailabilityKind::Deprecated;
53925402 else if (isNoAsync)
53935403 platformAgnostic = PlatformAgnosticAvailabilityKind::NoAsync;
5394- else if (((PlatformKind) platform) == PlatformKind::none &&
5404+ else if (platform == PlatformKind::none &&
53955405 (!Introduced.empty () || !Deprecated.empty () || !Obsoleted.empty ()))
53965406 platformAgnostic =
53975407 isPackageDescriptionVersionSpecific
@@ -5402,9 +5412,9 @@ DeclDeserializer::readAvailable_DECL_ATTR(SmallVectorImpl<uint64_t> &scratch,
54025412 platformAgnostic = PlatformAgnosticAvailabilityKind::None;
54035413
54045414 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);
54085418 return attr;
54095419}
54105420
@@ -5643,7 +5653,11 @@ llvm::Error DeclDeserializer::deserializeDeclCommon() {
56435653 }
56445654
56455655 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 ();
56475661 break ;
56485662 }
56495663
@@ -5753,7 +5767,10 @@ llvm::Error DeclDeserializer::deserializeDeclCommon() {
57535767 }
57545768
57555769 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 ());
57575774 restoreOffset2.cancel ();
57585775 --numAvailabilityAttrs;
57595776 }
0 commit comments