Skip to content

Commit 95e9646

Browse files
authored
Merge pull request #20196 from gottesmm/pr-287632bfd462700721e50c144278d5edb97f6b6a
[silgen] Scope conditionally emitted code by emitBoolDispatch.
2 parents 47c1aa7 + b45bea8 commit 95e9646

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

lib/SILGen/SILGenPattern.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2267,6 +2267,9 @@ emitBoolDispatch(ArrayRef<RowToSpecialize> rows, ConsumableManagedValue src,
22672267
SILBasicBlock *caseBB = caseBBs[i].second;
22682268
SGF.B.setInsertionPoint(caseBB);
22692269

2270+
// We're in conditionally-executed code; enter a scope.
2271+
Scope scope(SGF.Cleanups, CleanupLocation::get(loc));
2272+
22702273
SILValue result
22712274
= SILUndef::get(SGF.SGM.Types.getEmptyTupleType(), SGF.SGM.M);
22722275
ConsumableManagedValue CMV =

test/SILGen/Inputs/switch_bool.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
@import Foundation;
3+
4+
typedef NSString * MyStringEnum NS_EXTENSIBLE_STRING_ENUM;
5+
extern MyStringEnum const MyStringEnumCase1;
6+
extern MyStringEnum const MyStringEnumCase2;
7+
extern MyStringEnum const MyStringEnumCase3;
8+
extern MyStringEnum const MyStringEnumCase4;

test/SILGen/switch_bool.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %target-swift-emit-silgen -module-name switch_bool -import-objc-header %S/Inputs/switch_bool.h %s
2+
3+
// REQUIRES: objc_interop
4+
5+
// For now this test just makes sure that we do not crash on this pattern by
6+
// running into dominance problems due to not-scoping the subcases of the
7+
// SwitchValue. So performing a FileCheck test is not really needed. Feel free
8+
// to add the FileCheck invocation if additional tests require FileCheck though.
9+
10+
func properlyScopeSubcasesOfEmitBoolDispatch() {
11+
let e = Optional<MyStringEnum>.none
12+
switch (e, false) {
13+
case (MyStringEnum.case1?, false):
14+
break
15+
case (let e?, _):
16+
let y = {
17+
return e
18+
}
19+
default:
20+
break
21+
}
22+
}

0 commit comments

Comments
 (0)