@@ -457,7 +457,8 @@ class PatternMatchEmission {
457
457
void emitDestructiveCaseBlocks ();
458
458
459
459
JumpDest getSharedCaseBlockDest (CaseStmt *caseStmt);
460
- void emitSharedCaseBlocks (llvm::function_ref<void (CaseStmt *)> bodyEmitter);
460
+ void emitSharedCaseBlocks (ValueOwnership ownership,
461
+ llvm::function_ref<void (CaseStmt *)> bodyEmitter);
461
462
462
463
void emitCaseBody (CaseStmt *caseBlock);
463
464
@@ -2790,8 +2791,13 @@ void PatternMatchEmission::emitDestructiveCaseBlocks() {
2790
2791
// TODO: handle fallthroughs and multiple cases bindings
2791
2792
// In those cases we'd need to forward bindings through the shared case
2792
2793
// destination blocks.
2793
- assert (!stmt->hasFallthroughDest ()
2794
- && stmt->getCaseLabelItems ().size () == 1 );
2794
+ if (stmt->hasFallthroughDest ()
2795
+ || stmt->getCaseLabelItems ().size () != 1 ) {
2796
+ // This should already have been diagnosed as unsupported, so just emit
2797
+ // an unreachable here.
2798
+ SGF.B .createUnreachable (stmt);
2799
+ continue ;
2800
+ }
2795
2801
2796
2802
// Bind variables from the pattern.
2797
2803
if (stmt->hasCaseBodyVariables ()) {
@@ -2899,7 +2905,21 @@ emitAddressOnlyInitialization(VarDecl *dest, SILValue value) {
2899
2905
2900
2906
// / Emit all the shared case statements.
2901
2907
void PatternMatchEmission::emitSharedCaseBlocks (
2908
+ ValueOwnership ownership,
2902
2909
llvm::function_ref<void (CaseStmt *)> bodyEmitter) {
2910
+ if (ownership >= ValueOwnership::Shared
2911
+ && !SharedCases.empty ()) {
2912
+ SGF.SGM .diagnose (SharedCases.front ().first ,
2913
+ diag::noncopyable_shared_case_block_unimplemented);
2914
+
2915
+ for (auto &entry : SharedCases) {
2916
+ SILBasicBlock *caseBB = entry.second .first ;
2917
+ SGF.B .setInsertionPoint (caseBB);
2918
+ SGF.B .createUnreachable (entry.first );
2919
+ }
2920
+
2921
+ return ;
2922
+ }
2903
2923
for (auto &entry : SharedCases) {
2904
2924
CaseStmt *caseBlock = entry.first ;
2905
2925
SILBasicBlock *caseBB = entry.second .first ;
@@ -3742,7 +3762,7 @@ void SILGenFunction::emitSwitchStmt(SwitchStmt *S) {
3742
3762
}
3743
3763
3744
3764
// Then emit the case blocks shared by multiple pattern cases.
3745
- emission.emitSharedCaseBlocks (
3765
+ emission.emitSharedCaseBlocks (ownership,
3746
3766
[&](CaseStmt *caseStmt) { emission.emitCaseBody (caseStmt); });
3747
3767
3748
3768
// Bookkeeping.
@@ -4015,7 +4035,8 @@ void SILGenFunction::emitCatchDispatch(DoCatchStmt *S, ManagedValue exn,
4015
4035
stmtScope.pop ();
4016
4036
4017
4037
// Then emit the case blocks shared by multiple pattern cases.
4018
- emission.emitSharedCaseBlocks ([&](CaseStmt *caseStmt) {
4038
+ emission.emitSharedCaseBlocks (ValueOwnership::Default,
4039
+ [&](CaseStmt *caseStmt) {
4019
4040
emitStmt (caseStmt->getBody ());
4020
4041
4021
4042
// If we fell out of the catch clause, branch to the fallthrough dest.
0 commit comments