Skip to content

Commit 7772415

Browse files
authored
Merge pull request #14641 from gottesmm/pr-3aaad2fed3dce4737ba129e61694d0530d801995
2 parents b6bbe31 + 499e59c commit 7772415

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

lib/SILGen/SILGenPoly.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,11 @@ namespace {
11201120
SGF.B.createInjectEnumAddr(Loc, optionalBuf, someDecl);
11211121

11221122
auto payload = tupleTemp->getManagedAddress();
1123-
return ManagedValue(optionalBuf, payload.getCleanup());
1123+
if (payload.hasCleanup()) {
1124+
payload.forward(SGF);
1125+
return SGF.emitManagedBufferWithCleanup(optionalBuf);
1126+
}
1127+
return ManagedValue::forUnmanaged(optionalBuf);
11241128
}
11251129
}
11261130

@@ -1150,15 +1154,20 @@ namespace {
11501154

11511155
auto payload = tupleTemp->getManagedAddress();
11521156
if (SGF.silConv.useLoweredAddresses()) {
1153-
return ManagedValue(existentialBuf, payload.getCleanup());
1157+
// We always need to return the existential buf with a cleanup even if
1158+
// we stored trivial values, since SILGen maintains the invariant that
1159+
// forwarding a non-trivial value (i.e. an Any) into memory must be done
1160+
// at +1.
1161+
payload.forward(SGF);
1162+
return SGF.emitManagedBufferWithCleanup(existentialBuf);
11541163
}
1164+
11551165
// We are under opaque value(s) mode - load the any and init an opaque
1156-
auto loadedPayload = SGF.emitManagedLoadCopy(Loc, payload.getValue());
1166+
auto loadedPayload = SGF.B.createLoadCopy(Loc, payload);
11571167
auto &anyTL = SGF.getTypeLowering(opaque, outputSubstType);
1158-
SILValue loadedOpaque = SGF.B.createInitExistentialValue(
1159-
Loc, anyTL.getLoweredType(), inputTupleType, loadedPayload.getValue(),
1168+
return SGF.B.createInitExistentialValue(
1169+
Loc, anyTL.getLoweredType(), inputTupleType, loadedPayload,
11601170
/*Conformances=*/{});
1161-
return ManagedValue(loadedOpaque, loadedPayload.getCleanup());
11621171
}
11631172

11641173
/// Handle a tuple that has been exploded in both the input and

0 commit comments

Comments
 (0)