Skip to content

Commit 31efc6a

Browse files
committed
SILGen: Use emitOpenExistentialLValue() when lowering OpenExistentialExprs with lvalue base
1 parent 82ef5b3 commit 31efc6a

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

lib/SILGen/SILGenExpr.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4047,29 +4047,33 @@ void SILGenFunction::emitOpenExistentialExprImpl(
40474047
llvm::function_ref<void(Expr *)> emitSubExpr) {
40484048
Optional<FormalEvaluationScope> writebackScope;
40494049

4050+
Type opaqueValueType = E->getOpaqueValue()->getType()->getRValueType();
4051+
40504052
// Emit the existential value.
4051-
ManagedValue existentialValue;
4053+
SILGenFunction::OpaqueValueState state;
4054+
40524055
AccessKind accessKind;
40534056
if (E->getExistentialValue()->getType()->is<LValueType>()) {
40544057
// Create a writeback scope for the access to the existential lvalue.
40554058
writebackScope.emplace(*this);
40564059

40574060
accessKind = E->getExistentialValue()->getLValueAccessKind();
4058-
existentialValue = emitAddressOfLValue(
4059-
E->getExistentialValue(),
4060-
emitLValue(E->getExistentialValue(), accessKind),
4061-
accessKind);
4061+
auto lv = emitLValue(E->getExistentialValue(), accessKind);
4062+
lv = emitOpenExistentialLValue(E, std::move(lv),
4063+
CanArchetypeType(E->getOpenedArchetype()),
4064+
accessKind);
4065+
auto addr = emitAddressOfLValue(E, std::move(lv), accessKind);
4066+
state = {addr, false, false};
40624067
} else {
40634068
accessKind = AccessKind::Read;
4064-
existentialValue = emitRValueAsSingleValue(
4065-
E->getExistentialValue(),
4066-
SGFContext::AllowGuaranteedPlusZero);
4067-
}
4069+
auto existentialValue = emitRValueAsSingleValue(
4070+
E->getExistentialValue(),
4071+
SGFContext::AllowGuaranteedPlusZero);
40684072

4069-
Type opaqueValueType = E->getOpaqueValue()->getType()->getRValueType();
4070-
SILGenFunction::OpaqueValueState state = emitOpenExistential(
4073+
state = emitOpenExistential(
40714074
E, existentialValue, E->getOpenedArchetype(),
40724075
getLoweredType(opaqueValueType), accessKind);
4076+
}
40734077

40744078
// Register the opaque value for the projected existential.
40754079
SILGenFunction::OpaqueValueRAII opaqueValueRAII(

lib/SILGen/SILGenFunction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
957957
/// \param openedArchetype The opened existential archetype.
958958
/// \param loweredOpenedType The lowered type of the projection, which in
959959
/// practice will be the openedArchetype, possibly wrapped in a metatype.
960-
SILGenFunction::OpaqueValueState
960+
OpaqueValueState
961961
emitOpenExistential(SILLocation loc,
962962
ManagedValue existentialValue,
963963
ArchetypeType *openedArchetype,

0 commit comments

Comments
 (0)