@@ -457,7 +457,8 @@ class PatternMatchEmission {
457457 void emitDestructiveCaseBlocks ();
458458
459459 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);
461462
462463 void emitCaseBody (CaseStmt *caseBlock);
463464
@@ -2790,8 +2791,13 @@ void PatternMatchEmission::emitDestructiveCaseBlocks() {
27902791 // TODO: handle fallthroughs and multiple cases bindings
27912792 // In those cases we'd need to forward bindings through the shared case
27922793 // 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+ }
27952801
27962802 // Bind variables from the pattern.
27972803 if (stmt->hasCaseBodyVariables ()) {
@@ -2899,7 +2905,21 @@ emitAddressOnlyInitialization(VarDecl *dest, SILValue value) {
28992905
29002906// / Emit all the shared case statements.
29012907void PatternMatchEmission::emitSharedCaseBlocks (
2908+ ValueOwnership ownership,
29022909 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+ }
29032923 for (auto &entry : SharedCases) {
29042924 CaseStmt *caseBlock = entry.first ;
29052925 SILBasicBlock *caseBB = entry.second .first ;
@@ -3742,7 +3762,7 @@ void SILGenFunction::emitSwitchStmt(SwitchStmt *S) {
37423762 }
37433763
37443764 // Then emit the case blocks shared by multiple pattern cases.
3745- emission.emitSharedCaseBlocks (
3765+ emission.emitSharedCaseBlocks (ownership,
37463766 [&](CaseStmt *caseStmt) { emission.emitCaseBody (caseStmt); });
37473767
37483768 // Bookkeeping.
@@ -4015,7 +4035,8 @@ void SILGenFunction::emitCatchDispatch(DoCatchStmt *S, ManagedValue exn,
40154035 stmtScope.pop ();
40164036
40174037 // Then emit the case blocks shared by multiple pattern cases.
4018- emission.emitSharedCaseBlocks ([&](CaseStmt *caseStmt) {
4038+ emission.emitSharedCaseBlocks (ValueOwnership::Default,
4039+ [&](CaseStmt *caseStmt) {
40194040 emitStmt (caseStmt->getBody ());
40204041
40214042 // If we fell out of the catch clause, branch to the fallthrough dest.
0 commit comments