@@ -540,23 +540,44 @@ class MetadataReader {
540
540
llvm::Optional<uint32_t >
541
541
readGenericArgsOffset (MetadataRef metadata,
542
542
ContextDescriptorRef descriptor) {
543
- auto type = cast<TargetTypeContextDescriptor<Runtime>>(descriptor);
544
- if (auto *classMetadata = dyn_cast<TargetClassMetadata<Runtime>>(metadata)){
545
- if (classMetadata->SuperClass ) {
546
- auto superMetadata = readMetadata (classMetadata->SuperClass );
547
- if (!superMetadata)
548
- return llvm::None;
543
+ switch (descriptor->getKind ()) {
544
+ case ContextDescriptorKind::Class: {
545
+ auto type = cast<TargetClassDescriptor<Runtime>>(descriptor);
549
546
550
- auto result =
551
- type->getGenericArgumentOffset (
552
- classMetadata,
553
- cast<TargetClassMetadata<Runtime>>(superMetadata));
547
+ auto *classMetadata = dyn_cast<TargetClassMetadata<Runtime>>(metadata);
548
+ if (!classMetadata)
549
+ return llvm::None;
554
550
555
- return result;
556
- }
551
+ if (!classMetadata->SuperClass )
552
+ return type->getGenericArgumentOffset (nullptr , nullptr );
553
+
554
+ auto superMetadata = readMetadata (classMetadata->SuperClass );
555
+ if (!superMetadata)
556
+ return llvm::None;
557
+
558
+ auto superClassMetadata =
559
+ dyn_cast<TargetClassMetadata<Runtime>>(superMetadata);
560
+ if (!superClassMetadata)
561
+ return llvm::None;
562
+
563
+ auto result =
564
+ type->getGenericArgumentOffset (classMetadata, superClassMetadata);
565
+ return result;
566
+ }
567
+
568
+ case ContextDescriptorKind::Enum: {
569
+ auto type = cast<TargetEnumDescriptor<Runtime>>(descriptor);
570
+ return type->getGenericArgumentOffset ();
557
571
}
558
572
559
- return type->getGenericArgumentOffset ();
573
+ case ContextDescriptorKind::Struct: {
574
+ auto type = cast<TargetStructDescriptor<Runtime>>(descriptor);
575
+ return type->getGenericArgumentOffset ();
576
+ }
577
+
578
+ default :
579
+ return llvm::None;
580
+ }
560
581
}
561
582
562
583
// / Read a single generic type argument from a bound generic type
@@ -959,15 +980,21 @@ class MetadataReader {
959
980
case ContextDescriptorKind::Anonymous:
960
981
baseSize = sizeof (TargetAnonymousContextDescriptor<Runtime>);
961
982
break ;
983
+ case ContextDescriptorKind::Class:
984
+ baseSize = sizeof (TargetClassDescriptor<Runtime>);
985
+ genericHeaderSize = sizeof (TypeGenericContextDescriptorHeader);
986
+ hasVTable = flags.getKindSpecificFlags ()
987
+ & (uint16_t )TypeContextDescriptorFlags::HasVTable;
988
+ break ;
989
+ case ContextDescriptorKind::Enum:
990
+ baseSize = sizeof (TargetEnumDescriptor<Runtime>);
991
+ genericHeaderSize = sizeof (TypeGenericContextDescriptorHeader);
992
+ break ;
993
+ case ContextDescriptorKind::Struct:
994
+ baseSize = sizeof (TargetStructDescriptor<Runtime>);
995
+ genericHeaderSize = sizeof (TypeGenericContextDescriptorHeader);
996
+ break ;
962
997
default :
963
- if (kind >= ContextDescriptorKind::Type_First
964
- && kind <= ContextDescriptorKind::Type_Last) {
965
- baseSize = sizeof (TargetTypeContextDescriptor<Runtime>);
966
- genericHeaderSize = sizeof (TypeGenericContextDescriptorHeader);
967
- hasVTable = flags.getKindSpecificFlags ()
968
- & (uint16_t )TypeContextDescriptorFlags::HasVTable;
969
- break ;
970
- }
971
998
// We don't know about this kind of context.
972
999
return nullptr ;
973
1000
}
0 commit comments