@@ -1166,6 +1166,28 @@ static SILInstruction *isSuperInitUse(UpcastInst *Inst) {
1166
1166
return nullptr ;
1167
1167
}
1168
1168
1169
+ static bool isUninitializedMetatypeInst (SILInstruction *I) {
1170
+ // A simple reference to "type(of:)" is always fine,
1171
+ // even if self is uninitialized.
1172
+ if (isa<ValueMetatypeInst>(I))
1173
+ return true ;
1174
+
1175
+ // Sometimes we get an upcast whose sole usage is a value_metatype_inst,
1176
+ // for example when calling a convenience initializer from a superclass.
1177
+ if (auto *UCI = dyn_cast<UpcastInst>(I)) {
1178
+ for (auto *UI : UCI->getUses ()) {
1179
+ auto *User = UI->getUser ();
1180
+ if (isa<ValueMetatypeInst>(User))
1181
+ continue ;
1182
+ return false ;
1183
+ }
1184
+
1185
+ return true ;
1186
+ }
1187
+
1188
+ return false ;
1189
+ }
1190
+
1169
1191
// / isSelfInitUse - Return true if this apply_inst is a call to self.init.
1170
1192
static bool isSelfInitUse (SILInstruction *I) {
1171
1193
// If we're reading a .sil file, treat a call to "selfinit" as a
@@ -1354,11 +1376,8 @@ void ElementUseCollector::collectClassSelfUses(
1354
1376
Kind = DIUseKind::SelfInit;
1355
1377
UseInfo.trackFailableInitCall (TheMemory, User);
1356
1378
}
1357
-
1358
- // If this is a ValueMetatypeInst, this is a simple reference
1359
- // to "type(of:)", which is always fine, even if self is
1360
- // uninitialized.
1361
- if (isa<ValueMetatypeInst>(User))
1379
+
1380
+ if (isUninitializedMetatypeInst (User))
1362
1381
continue ;
1363
1382
1364
1383
// If this is a partial application of self, then this is an escape point
@@ -1630,11 +1649,8 @@ void DelegatingInitElementUseCollector::collectDelegatingClassInitSelfLoadUses(
1630
1649
}
1631
1650
}
1632
1651
1633
- // A simple reference to "type(of:)" is always fine,
1634
- // even if self is uninitialized.
1635
- if (isa<ValueMetatypeInst>(User)) {
1652
+ if (isUninitializedMetatypeInst (User))
1636
1653
continue ;
1637
- }
1638
1654
1639
1655
UseInfo.trackUse (DIMemoryUse (User, Kind, 0 , 1 ));
1640
1656
}
0 commit comments