@@ -983,18 +983,28 @@ getAddrOfKnownValueWitnessTable(IRGenModule &IGM, CanType type) {
983
983
984
984
if (auto nom = type->getAnyNominal ()) {
985
985
// TODO: Generic metadata patterns relative-reference their VWT, which won't
986
- // work if it's in a different module without supporting indirection through
987
- // the GOT.
986
+ // work if the VWT is in a different module without supporting indirection
987
+ // through the GOT.
988
988
if (nom->isGenericContext ())
989
989
return nullptr ;
990
- // TODO: Enums need additional value witnesses for their tag manipulation.
991
- if (isa<EnumDecl>(nom))
992
- return nullptr ;
990
+ // TODO: Non-C enums have extra inhabitants and also need additional value
991
+ // witnesses for their tag manipulation (except when they're empty, in
992
+ // which case values never exist to witness).
993
+ if (auto enumDecl = dyn_cast<EnumDecl>(nom))
994
+ if (!enumDecl->isObjC () && !type->isUninhabited ())
995
+ return nullptr ;
993
996
}
994
-
997
+
998
+ auto &C = IGM.Context ;
999
+
995
1000
type = getFormalTypeInContext (type);
996
1001
997
1002
auto &ti = IGM.getTypeInfoForUnlowered (AbstractionPattern::getOpaque (), type);
1003
+
1004
+ // Empty types can use empty tuple witnesses.
1005
+ if (ti.isKnownEmpty (ResilienceExpansion::Maximal))
1006
+ return IGM.getAddrOfValueWitnessTable (TupleType::getEmpty (C));
1007
+
998
1008
// We only have witnesses for fixed type info.
999
1009
auto *fixedTI = dyn_cast<FixedTypeInfo>(&ti);
1000
1010
if (!fixedTI)
@@ -1003,7 +1013,6 @@ getAddrOfKnownValueWitnessTable(IRGenModule &IGM, CanType type) {
1003
1013
CanType witnessSurrogate;
1004
1014
1005
1015
// Handle common POD type layouts.
1006
- auto &C = type->getASTContext ();
1007
1016
ReferenceCounting refCounting;
1008
1017
if (fixedTI->isPOD (ResilienceExpansion::Maximal)
1009
1018
&& fixedTI->getFixedExtraInhabitantCount (IGM) == 0 ) {
0 commit comments