Skip to content

Commit 13f8f73

Browse files
authored
Merge pull request #36063 from meg-gupta/fixcloneforwardingownership
While cloning OwnershipForwardingConversionInst make sure to copy forwardingOwnershipKind from the original instruction
2 parents 43c7ad7 + 333f63e commit 13f8f73

File tree

5 files changed

+202
-89
lines changed

5 files changed

+202
-89
lines changed

include/swift/SIL/SILBuilder.h

Lines changed: 67 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,9 +1028,17 @@ class SILBuilder {
10281028
ConvertFunctionInst *createConvertFunction(SILLocation Loc, SILValue Op,
10291029
SILType Ty,
10301030
bool WithoutActuallyEscaping) {
1031-
return insert(ConvertFunctionInst::create(getSILDebugLocation(Loc), Op, Ty,
1032-
getModule(), F, C.OpenedArchetypes,
1033-
WithoutActuallyEscaping));
1031+
return createConvertFunction(Loc, Op, Ty, WithoutActuallyEscaping,
1032+
Op.getOwnershipKind());
1033+
}
1034+
1035+
ConvertFunctionInst *
1036+
createConvertFunction(SILLocation Loc, SILValue Op, SILType Ty,
1037+
bool WithoutActuallyEscaping,
1038+
ValueOwnershipKind forwardingOwnershipKind) {
1039+
return insert(ConvertFunctionInst::create(
1040+
getSILDebugLocation(Loc), Op, Ty, getModule(), F, C.OpenedArchetypes,
1041+
WithoutActuallyEscaping, forwardingOwnershipKind));
10341042
}
10351043

10361044
ConvertEscapeToNoEscapeInst *
@@ -1054,8 +1062,14 @@ class SILBuilder {
10541062
}
10551063

10561064
UpcastInst *createUpcast(SILLocation Loc, SILValue Op, SILType Ty) {
1065+
return createUpcast(Loc, Op, Ty, Op.getOwnershipKind());
1066+
}
1067+
1068+
UpcastInst *createUpcast(SILLocation Loc, SILValue Op, SILType Ty,
1069+
ValueOwnershipKind forwardingOwnershipKind) {
10571070
return insert(UpcastInst::create(getSILDebugLocation(Loc), Op, Ty,
1058-
getFunction(), C.OpenedArchetypes));
1071+
getFunction(), C.OpenedArchetypes,
1072+
forwardingOwnershipKind));
10591073
}
10601074

10611075
AddressToPointerInst *createAddressToPointer(SILLocation Loc, SILValue Op,
@@ -1075,7 +1089,16 @@ class SILBuilder {
10751089
UncheckedRefCastInst *createUncheckedRefCast(SILLocation Loc, SILValue Op,
10761090
SILType Ty) {
10771091
return insert(UncheckedRefCastInst::create(
1078-
getSILDebugLocation(Loc), Op, Ty, getFunction(), C.OpenedArchetypes));
1092+
getSILDebugLocation(Loc), Op, Ty, getFunction(), C.OpenedArchetypes,
1093+
Op.getOwnershipKind()));
1094+
}
1095+
1096+
UncheckedRefCastInst *
1097+
createUncheckedRefCast(SILLocation Loc, SILValue Op, SILType Ty,
1098+
ValueOwnershipKind forwardingOwnershipKind) {
1099+
return insert(UncheckedRefCastInst::create(
1100+
getSILDebugLocation(Loc), Op, Ty, getFunction(), C.OpenedArchetypes,
1101+
forwardingOwnershipKind));
10791102
}
10801103

10811104
UncheckedRefCastAddrInst *
@@ -1107,22 +1130,41 @@ class SILBuilder {
11071130

11081131
UncheckedValueCastInst *createUncheckedValueCast(SILLocation Loc, SILValue Op,
11091132
SILType Ty) {
1133+
return createUncheckedValueCast(Loc, Op, Ty, Op.getOwnershipKind());
1134+
}
1135+
1136+
UncheckedValueCastInst *
1137+
createUncheckedValueCast(SILLocation Loc, SILValue Op, SILType Ty,
1138+
ValueOwnershipKind forwardingOwnershipKind) {
11101139
assert(hasOwnership());
11111140
return insert(UncheckedValueCastInst::create(
1112-
getSILDebugLocation(Loc), Op, Ty, getFunction(), C.OpenedArchetypes));
1141+
getSILDebugLocation(Loc), Op, Ty, getFunction(), C.OpenedArchetypes,
1142+
forwardingOwnershipKind));
11131143
}
11141144

11151145
RefToBridgeObjectInst *createRefToBridgeObject(SILLocation Loc, SILValue Ref,
11161146
SILValue Bits) {
1147+
return createRefToBridgeObject(Loc, Ref, Bits, Ref.getOwnershipKind());
1148+
}
1149+
1150+
RefToBridgeObjectInst *
1151+
createRefToBridgeObject(SILLocation Loc, SILValue Ref, SILValue Bits,
1152+
ValueOwnershipKind forwardingOwnershipKind) {
11171153
auto Ty = SILType::getBridgeObjectType(getASTContext());
11181154
return insert(new (getModule()) RefToBridgeObjectInst(
1119-
getSILDebugLocation(Loc), Ref, Bits, Ty));
1155+
getSILDebugLocation(Loc), Ref, Bits, Ty, forwardingOwnershipKind));
11201156
}
11211157

11221158
BridgeObjectToRefInst *createBridgeObjectToRef(SILLocation Loc, SILValue Op,
11231159
SILType Ty) {
1160+
return createBridgeObjectToRef(Loc, Op, Ty, Op.getOwnershipKind());
1161+
}
1162+
1163+
BridgeObjectToRefInst *
1164+
createBridgeObjectToRef(SILLocation Loc, SILValue Op, SILType Ty,
1165+
ValueOwnershipKind forwardingOwnershipKind) {
11241166
return insert(new (getModule()) BridgeObjectToRefInst(
1125-
getSILDebugLocation(Loc), Op, Ty));
1167+
getSILDebugLocation(Loc), Op, Ty, forwardingOwnershipKind));
11261168
}
11271169

11281170
ValueToBridgeObjectInst *createValueToBridgeObject(SILLocation Loc,
@@ -1158,8 +1200,15 @@ class SILBuilder {
11581200

11591201
ThinToThickFunctionInst *createThinToThickFunction(SILLocation Loc,
11601202
SILValue Op, SILType Ty) {
1203+
return createThinToThickFunction(Loc, Op, Ty, Op.getOwnershipKind());
1204+
}
1205+
1206+
ThinToThickFunctionInst *
1207+
createThinToThickFunction(SILLocation Loc, SILValue Op, SILType Ty,
1208+
ValueOwnershipKind forwardingOwnershipKind) {
11611209
return insert(ThinToThickFunctionInst::create(
1162-
getSILDebugLocation(Loc), Op, Ty, getModule(), F, C.OpenedArchetypes));
1210+
getSILDebugLocation(Loc), Op, Ty, getModule(), F, C.OpenedArchetypes,
1211+
forwardingOwnershipKind));
11631212
}
11641213

11651214
ThickToObjCMetatypeInst *createThickToObjCMetatype(SILLocation Loc,
@@ -1201,9 +1250,17 @@ class SILBuilder {
12011250
createUnconditionalCheckedCast(SILLocation Loc, SILValue op,
12021251
SILType destLoweredTy,
12031252
CanType destFormalTy) {
1253+
return createUnconditionalCheckedCast(Loc, op, destLoweredTy, destFormalTy,
1254+
op.getOwnershipKind());
1255+
}
1256+
1257+
UnconditionalCheckedCastInst *
1258+
createUnconditionalCheckedCast(SILLocation Loc, SILValue op,
1259+
SILType destLoweredTy, CanType destFormalTy,
1260+
ValueOwnershipKind forwardingOwnershipKind) {
12041261
return insert(UnconditionalCheckedCastInst::create(
12051262
getSILDebugLocation(Loc), op, destLoweredTy, destFormalTy,
1206-
getFunction(), C.OpenedArchetypes));
1263+
getFunction(), C.OpenedArchetypes, forwardingOwnershipKind));
12071264
}
12081265

12091266
UnconditionalCheckedCastAddrInst *

include/swift/SIL/SILCloner.h

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,7 +1405,8 @@ SILCloner<ImplClass>::visitConvertFunctionInst(ConvertFunctionInst *Inst) {
14051405
recordClonedInstruction(
14061406
Inst, getBuilder().createConvertFunction(
14071407
getOpLocation(Inst->getLoc()), getOpValue(Inst->getOperand()),
1408-
getOpType(Inst->getType()), Inst->withoutActuallyEscaping()));
1408+
getOpType(Inst->getType()), Inst->withoutActuallyEscaping(),
1409+
Inst->getForwardingOwnershipKind()));
14091410
}
14101411

14111412
template <typename ImplClass>
@@ -1445,7 +1446,8 @@ SILCloner<ImplClass>::visitUpcastInst(UpcastInst *Inst) {
14451446
recordClonedInstruction(
14461447
Inst, getBuilder().createUpcast(getOpLocation(Inst->getLoc()),
14471448
getOpValue(Inst->getOperand()),
1448-
getOpType(Inst->getType())));
1449+
getOpType(Inst->getType()),
1450+
Inst->getForwardingOwnershipKind()));
14491451
}
14501452

14511453
template<typename ImplClass>
@@ -1474,10 +1476,11 @@ void
14741476
SILCloner<ImplClass>::
14751477
visitUncheckedRefCastInst(UncheckedRefCastInst *Inst) {
14761478
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
1477-
recordClonedInstruction(
1478-
Inst, getBuilder().createUncheckedRefCast(getOpLocation(Inst->getLoc()),
1479-
getOpValue(Inst->getOperand()),
1480-
getOpType(Inst->getType())));
1479+
recordClonedInstruction(Inst, getBuilder().createUncheckedRefCast(
1480+
getOpLocation(Inst->getLoc()),
1481+
getOpValue(Inst->getOperand()),
1482+
getOpType(Inst->getType()),
1483+
Inst->getForwardingOwnershipKind()));
14811484
}
14821485

14831486
template<typename ImplClass>
@@ -1542,7 +1545,8 @@ void SILCloner<ImplClass>::visitUncheckedValueCastInst(
15421545
recordClonedInstruction(Inst, getBuilder().createUncheckedValueCast(
15431546
getOpLocation(Inst->getLoc()),
15441547
getOpValue(Inst->getOperand()),
1545-
getOpType(Inst->getType())));
1548+
getOpType(Inst->getType()),
1549+
Inst->getForwardingOwnershipKind()));
15461550
}
15471551

15481552
template<typename ImplClass>
@@ -1553,7 +1557,8 @@ visitRefToBridgeObjectInst(RefToBridgeObjectInst *Inst) {
15531557
recordClonedInstruction(Inst, getBuilder().createRefToBridgeObject(
15541558
getOpLocation(Inst->getLoc()),
15551559
getOpValue(Inst->getConverted()),
1556-
getOpValue(Inst->getBitsOperand())));
1560+
getOpValue(Inst->getBitsOperand()),
1561+
Inst->getForwardingOwnershipKind()));
15571562
}
15581563

15591564
template<typename ImplClass>
@@ -1564,7 +1569,8 @@ visitBridgeObjectToRefInst(BridgeObjectToRefInst *Inst) {
15641569
recordClonedInstruction(Inst, getBuilder().createBridgeObjectToRef(
15651570
getOpLocation(Inst->getLoc()),
15661571
getOpValue(Inst->getConverted()),
1567-
getOpType(Inst->getType())));
1572+
getOpType(Inst->getType()),
1573+
Inst->getForwardingOwnershipKind()));
15681574
}
15691575

15701576
template<typename ImplClass>
@@ -1615,7 +1621,8 @@ visitThinToThickFunctionInst(ThinToThickFunctionInst *Inst) {
16151621
recordClonedInstruction(Inst, getBuilder().createThinToThickFunction(
16161622
getOpLocation(Inst->getLoc()),
16171623
getOpValue(Inst->getOperand()),
1618-
getOpType(Inst->getType())));
1624+
getOpType(Inst->getType()),
1625+
Inst->getForwardingOwnershipKind()));
16191626
}
16201627

16211628
template<typename ImplClass>
@@ -1650,8 +1657,8 @@ SILCloner<ImplClass>::visitUnconditionalCheckedCastInst(
16501657
CanType OpFormalType = getOpASTType(Inst->getTargetFormalType());
16511658
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
16521659
recordClonedInstruction(Inst, getBuilder().createUnconditionalCheckedCast(
1653-
OpLoc, OpValue,
1654-
OpLoweredType, OpFormalType));
1660+
OpLoc, OpValue, OpLoweredType, OpFormalType,
1661+
Inst->getForwardingOwnershipKind()));
16551662
}
16561663

16571664
template<typename ImplClass>

0 commit comments

Comments
 (0)