Skip to content

Commit 3480eec

Browse files
committed
Fix SILGen to generate switch_enum at +1 for opaque value operand
1 parent 2398181 commit 3480eec

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/SILGen/SILGenPattern.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2850,7 +2850,11 @@ void SILGenFunction::emitSwitchStmt(SwitchStmt *S) {
28502850
}
28512851

28522852
// If then we have an object, return it at +0.
2853+
// For opaque values, return at +1
28532854
if (subjectMV.getType().isObject()) {
2855+
if (subjectMV.getType().isAddressOnly(F)) {
2856+
return {subjectMV.copy(*this, S), CastConsumptionKind::TakeAlways};
2857+
}
28542858
return {subjectMV, CastConsumptionKind::BorrowAlways};
28552859
}
28562860

test/SILGen/opaque_values_silgen.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,3 +461,20 @@ class TestGeneric<T> {
461461
// CHECK: unwind
462462
// CHECK-LABEL: } // end sil function '$s20opaque_values_silgen11TestGenericC08borrowedE0xvr'
463463

464+
// CHECK-LABEL: sil hidden [ossa] @$s20opaque_values_silgen8TestEnumO5_codeSivg :
465+
// CHECK: bb0(%0 : @guaranteed $TestEnum<T>):
466+
// CHECK: [[COPY:%.*]] = copy_value %0 : $TestEnum<T>
467+
// CHECK: switch_enum [[COPY]] : $TestEnum<T>, case #TestEnum.invalidValue!enumelt: bb1
468+
// CHECK: bb1([[VAL:%.*]] : @owned $Any):
469+
// CHECK: destroy_value [[VAL]] : $Any
470+
// CHECK-LABEL: } // end sil function '$s20opaque_values_silgen8TestEnumO5_codeSivg'
471+
enum TestEnum<T> {
472+
case invalidValue(Any)
473+
474+
var _code: Int {
475+
switch self {
476+
case .invalidValue: return 4866
477+
}
478+
}
479+
}
480+

0 commit comments

Comments
 (0)