Skip to content

Commit 667f4e6

Browse files
author
Joe Shajrawi
authored
Merge pull request #8279 from shajrawi/opaque_if
Add support for if statements for opaque value(s) under new mode
2 parents 941a449 + a03f38c commit 667f4e6

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

lib/SILGen/SILGenExpr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2944,8 +2944,8 @@ RValue RValueEmitter::visitProtocolMetatypeToObjectExpr(
29442944

29452945
RValue RValueEmitter::visitIfExpr(IfExpr *E, SGFContext C) {
29462946
auto &lowering = SGF.getTypeLowering(E->getType());
2947-
2948-
if (lowering.isLoadable()) {
2947+
2948+
if (lowering.isLoadable() || !SGF.silConv.useLoweredAddresses()) {
29492949
// If the result is loadable, emit each branch and forward its result
29502950
// into the destination block argument.
29512951

test/SILGen/opaque_values_silgen.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,33 @@ func s340_______captureBox() {
648648
captureEverything()
649649
}
650650

651+
// Tests support for if statements for opaque value(s) under new mode
652+
// ---
653+
// CHECK-LABEL: sil hidden @_T020opaque_values_silgen21s350_______addrOnlyIfAA6EmptyP_pSb1x_tF : $@convention(thin) (Bool) -> @out EmptyP {
654+
// CHECK: bb0([[ARG:%.*]] : $Bool):
655+
// CHECK: [[ALLOC_OF_BOX:%.*]] = alloc_box ${ var EmptyP }, var
656+
// CHECK: [[PROJ_BOX:%.*]] = project_box [[ALLOC_OF_BOX]]
657+
// CHECK: [[APPLY_FOR_BOX:%.*]] = apply %{{.*}}(%{{.*}}) : $@convention(method) (@thin AddressOnlyStruct.Type) -> AddressOnlyStruct
658+
// CHECK: [[INIT_OPAQUE:%.*]] = init_existential_opaque [[APPLY_FOR_BOX]] : $AddressOnlyStruct, $AddressOnlyStruct, $EmptyP
659+
// CHECK: store [[INIT_OPAQUE]] to [init] [[PROJ_BOX]] : $*EmptyP
660+
// CHECK: [[APPLY_FOR_BRANCH:%.*]] = apply %{{.*}}([[ARG]]) : $@convention(method) (Bool) -> Builtin.Int1
661+
// CHECK: cond_br [[APPLY_FOR_BRANCH]], bb2, bb1
662+
// CHECK: bb1:
663+
// CHECK: [[RETVAL1:%.*]] = load [copy] [[PROJ_BOX]] : $*EmptyP
664+
// CHECK: br bb3([[RETVAL1]] : $EmptyP)
665+
// CHECK: bb2:
666+
// CHECK: [[RETVAL2:%.*]] = load [copy] [[PROJ_BOX]] : $*EmptyP
667+
// CHECK: br bb3([[RETVAL2]] : $EmptyP)
668+
// CHECK: bb3([[RETVAL:%.*]] : $EmptyP):
669+
// CHECK: destroy_value [[ALLOC_OF_BOX]]
670+
// CHECK: return [[RETVAL]] : $EmptyP
671+
// CHECK-LABEL: } // end sil function '_T020opaque_values_silgen21s350_______addrOnlyIfAA6EmptyP_pSb1x_tF'
672+
func s350_______addrOnlyIf(x: Bool) -> EmptyP {
673+
var a : EmptyP = AddressOnlyStruct()
674+
675+
return x ? a : a
676+
}
677+
651678
// Tests conditional value casts and correspondingly generated reabstraction thunk, with <T> types
652679
// ---
653680
// CHECK-LABEL: sil hidden @_T020opaque_values_silgen21s999_____condTFromAnyyyp_xtlF : $@convention(thin) <T> (@in Any, @in T) -> () {

0 commit comments

Comments
 (0)