Skip to content

Commit 8c48ca2

Browse files
committed
[OpaqueValues] Addr-only consumes emit loadably.
1 parent b15b4a0 commit 8c48ca2

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/SILGen/SILGenExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6199,7 +6199,7 @@ RValue RValueEmitter::visitConsumeExpr(ConsumeExpr *E, SGFContext C) {
61996199
return RValue(SGF, {optTemp->getManagedAddress()}, subType.getASTType());
62006200
}
62016201

6202-
if (subType.isLoadable(SGF.F)) {
6202+
if (subType.isLoadable(SGF.F) || !SGF.useLoweredAddresses()) {
62036203
ManagedValue mv = SGF.emitRValue(subExpr).getAsSingleValue(SGF, subExpr);
62046204
if (mv.getType().isTrivial(SGF.F))
62056205
return RValue(SGF, {mv}, subType.getASTType());

test/SILGen/opaque_values_silgen.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,3 +782,20 @@ func intIntoAnyHashableVar() {
782782
func intIntoAnyHashableLet() {
783783
let anyHashable: AnyHashable = 0
784784
}
785+
786+
// CHECK-LABEL: sil {{.*}}[ossa] @consumeExprOfOwnedAddrOnlyValue : {{.*}} {
787+
// CHECK: bb0([[T:%[^,]+]] :
788+
// CHECK: [[T_LIFETIME:%[^,]+]] = begin_borrow [[T]]
789+
// CHECK: [[T_COPY:%[^,]+]] = copy_value [[T_LIFETIME]]
790+
// CHECK: [[T_MOVE:%[^,]+]] = move_value [allows_diagnostics] [[T_COPY]]
791+
// CHECK: [[SINK:%[^,]+]] = function_ref @sink
792+
// CHECK: apply [[SINK]]<T>([[T_MOVE]])
793+
// CHECK: end_borrow [[T_LIFETIME]]
794+
// CHECK: destroy_value [[T]]
795+
// CHECK-LABEL: } // end sil function 'consumeExprOfOwnedAddrOnlyValue'
796+
@_silgen_name("consumeExprOfOwnedAddrOnlyValue")
797+
func consumeExprOfOwnedAddrOnlyValue<T>(_ t: __owned T) {
798+
sink(consume t)
799+
}
800+
@_silgen_name("sink")
801+
func sink<T>(_ t: consuming T) {}

0 commit comments

Comments
 (0)