Skip to content

Commit 9597195

Browse files
committed
[move-only] Fix a small thinko in the MoveOnlyBorrowToDestructureTransform.
Specifically, our operand /could/ be a SILArgument. In that case, oldInst in all of these cases will be a nullptr. So make sure to only delete them if we actually found a defining instruction.
1 parent 852911c commit 9597195

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lib/SILOptimizer/Mandatory/MoveOnlyBorrowToDestructureTransform.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,9 +1275,11 @@ void Implementation::rewriteUses(InstructionDeleter *deleter) {
12751275
first = builder.createOwnedMoveOnlyWrapperToCopyableValue(
12761276
getSafeLoc(inst), first);
12771277
}
1278+
// NOTE: oldInst may be nullptr if our operand is a SILArgument
1279+
// which can happen with switch_enum.
12781280
SILInstruction *oldInst = operand.get()->getDefiningInstruction();
12791281
operand.set(first);
1280-
if (deleter)
1282+
if (oldInst && deleter)
12811283
deleter->forceTrackAsDead(oldInst);
12821284
continue;
12831285
}
@@ -1309,9 +1311,11 @@ void Implementation::rewriteUses(InstructionDeleter *deleter) {
13091311
// NOTE: This needs to be /after/the interior pointer operand usage
13101312
// above so that we can use the end scope of our interior pointer base
13111313
// value.
1314+
// NOTE: oldInst may be nullptr if our operand is a SILArgument
1315+
// which can happen with switch_enum.
13121316
SILInstruction *oldInst = operand.get()->getDefiningInstruction();
13131317
operand.set(innerValue);
1314-
if (deleter)
1318+
if (oldInst && deleter)
13151319
deleter->forceTrackAsDead(oldInst);
13161320
continue;
13171321
}
@@ -1370,9 +1374,11 @@ void Implementation::rewriteUses(InstructionDeleter *deleter) {
13701374
borrowBuilder.createGuaranteedMoveOnlyWrapperToCopyableValue(
13711375
loc, value);
13721376
}
1377+
// NOTE: oldInst may be nullptr if our operand is a SILArgument
1378+
// which can happen with switch_enum.
13731379
auto *oldInst = operand.get()->getDefiningInstruction();
13741380
operand.set(value);
1375-
if (deleter)
1381+
if (oldInst && deleter)
13761382
deleter->forceTrackAsDead(oldInst);
13771383

13781384
// If we have a terminator that is a trivial use (e.x.: we
@@ -1443,9 +1449,11 @@ void Implementation::rewriteUses(InstructionDeleter *deleter) {
14431449
iterValue = consumeBuilder.createOwnedMoveOnlyWrapperToCopyableValue(
14441450
loc, iterValue);
14451451
}
1452+
// NOTE: oldInst may be nullptr if our operand is a SILArgument
1453+
// which can happen with switch_enum.
14461454
auto *oldInst = operand.get()->getDefiningInstruction();
14471455
operand.set(iterValue);
1448-
if (deleter)
1456+
if (oldInst && deleter)
14491457
deleter->forceTrackAsDead(oldInst);
14501458

14511459
// Then go through our available values and use the interval map to

0 commit comments

Comments
 (0)