Skip to content

Commit 22fdc89

Browse files
authored
Merge pull request swiftlang#8478 from gregomni/3518
[SILGen][SR-3518] Fix crasher getting wrong phi type in shared case block
2 parents 0c6f43a + b9ecde5 commit 22fdc89

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

lib/SILGen/SILGenPattern.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2292,7 +2292,7 @@ JumpDest PatternMatchEmission::getSharedCaseBlockDest(CaseStmt *caseBlock,
22922292
pattern->forEachVariable([&](VarDecl *V) {
22932293
if (!V->hasName())
22942294
return;
2295-
block->createPHIArgument(SGF.VarLocs[V].value->getType(),
2295+
block->createPHIArgument(SGF.getLoweredType(V->getType()),
22962296
ValueOwnershipKind::Owned, V);
22972297
});
22982298
}

test/SILGen/switch.swift

+26
Original file line numberDiff line numberDiff line change
@@ -1098,3 +1098,29 @@ func testOptionalEnumMixWithNil(_ a : Int?) -> Int {
10981098
// CHECK: integer_literal $Builtin.Int2048, 42
10991099
}
11001100
}
1101+
1102+
// SR-3518
1103+
// CHECK-LABEL: sil hidden @_T06switch43testMultiPatternsWithOuterScopeSameNamedVarySiSg4base_AC6filtertF
1104+
func testMultiPatternsWithOuterScopeSameNamedVar(base: Int?, filter: Int?) {
1105+
switch(base, filter) {
1106+
1107+
case (.some(let base), .some(let filter)):
1108+
// CHECK: bb2(%10 : $Int):
1109+
// CHECK-NEXT: debug_value %10 : $Int, let, name "base"
1110+
// CHECK-NEXT: debug_value %8 : $Int, let, name "filter"
1111+
print("both: \(base), \(filter)")
1112+
case (.some(let base), .none), (.none, .some(let base)):
1113+
// CHECK: bb3:
1114+
// CHECK-NEXT: debug_value %8 : $Int, let, name "base"
1115+
// CHECK-NEXT: br bb6(%8 : $Int)
1116+
1117+
// CHECK: bb5([[OTHER_BASE:%.*]] : $Int)
1118+
// CHECK-NEXT: debug_value [[OTHER_BASE]] : $Int, let, name "base"
1119+
// CHECK-NEXT: br bb6([[OTHER_BASE]] : $Int)
1120+
1121+
// CHECK: bb6([[ARG:%.*]] : $Int):
1122+
print("single: \(base)")
1123+
default:
1124+
print("default")
1125+
}
1126+
}

0 commit comments

Comments
 (0)