Skip to content

Commit a8b30b7

Browse files
authored
Merge pull request swiftlang#77916 from swiftlang/fix-condition-forwarding-6.1
[6.1] ConditionForwarding: fix a wrong assert
2 parents 380c92b + 619ce84 commit a8b30b7

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lib/SILOptimizer/Transforms/ConditionForwarding.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ bool ConditionForwarding::tryOptimize(SwitchEnumInst *SEI) {
237237
if (getFunction()->hasOwnership()) {
238238
// TODO: Currently disabled because this case may need lifetime extension
239239
// Disabling this conservatively for now.
240-
assert(Condition->getNumOperands() == 1);
240+
assert(Condition->getNumRealOperands() == 1);
241241
BorrowedValue conditionOp(Condition->getOperand(0));
242242
if (conditionOp && conditionOp.isLocalScope()) {
243243
return false;

test/SILOptimizer/conditionforwarding_ossa.sil

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class C {
1414
init()
1515
}
1616

17+
final class D: C {}
18+
1719
sil [ossa] @callee : $@convention(thin) () -> ()
1820
sil [ossa] @use_enum : $@convention(thin) (E) -> ()
1921
sil [ossa] @use_int : $@convention(thin) (Builtin.Int64) -> ()
@@ -388,3 +390,32 @@ bb6:
388390
return %r : $()
389391
}
390392

393+
// CHECK-LABEL: sil [ossa] @cast_with_type_dependent_operand :
394+
// CHECK-NOT: switch_enum
395+
// CHECK-LABEL: } // end sil function 'cast_with_type_dependent_operand'
396+
sil [ossa] @cast_with_type_dependent_operand : $@convention(method) (@guaranteed C, @guaranteed D) -> () {
397+
bb0(%0 : @guaranteed $C, %1 : @guaranteed $D):
398+
checked_cast_br C in %0 : $C to @dynamic_self D, bb1, bb2
399+
400+
bb1(%3 : @guaranteed $D):
401+
%4 = enum $Optional<D>, #Optional.some!enumelt, %3 : $D
402+
br bb3(%4 : $Optional<D>)
403+
404+
bb2(%6 : @guaranteed $C):
405+
%7 = enum $Optional<D>, #Optional.none!enumelt
406+
br bb3(%7 : $Optional<D>)
407+
408+
bb3(%9 : @guaranteed $Optional<D>):
409+
%10 = borrowed %9 : $Optional<D> from (%0 : $C)
410+
switch_enum %10 : $Optional<D>, case #Optional.some!enumelt: bb4, case #Optional.none!enumelt: bb5
411+
412+
bb4(%12 : @guaranteed $D):
413+
br bb6
414+
415+
bb5:
416+
br bb6
417+
418+
bb6:
419+
%15 = tuple ()
420+
return %15 : $()
421+
}

0 commit comments

Comments
 (0)