Skip to content

Commit 2ca8b15

Browse files
authored
Merge pull request #30610 from eeckstein/fix-destroy-hoisting
DestroyHoisting: fix a bug which creates invalid SIL
2 parents a856d59 + 15f519f commit 2ca8b15

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

lib/SILOptimizer/Transforms/DestroyHoisting.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -549,15 +549,17 @@ SILValue DestroyHoisting::createAddress(unsigned locIdx, SILBuilder &builder) {
549549
assert(!isa<BeginAccessInst>(loc->representativeValue) &&
550550
"only a root location can be a begin_access");
551551

552-
SingleValueInstruction *&cachedProj = addressProjections[locIdx];
553-
if (cachedProj)
554-
return cachedProj;
555-
556552
if (!domTree)
557553
domTree = DA->get(function);
554+
555+
SILInstruction *ip = &*builder.getInsertionPoint();
556+
557+
SingleValueInstruction *&cachedProj = addressProjections[locIdx];
558+
if (cachedProj && domTree->properlyDominates(cachedProj, ip))
559+
return cachedProj;
558560

559561
auto *projInst = cast<SingleValueInstruction>(loc->representativeValue);
560-
if (domTree->properlyDominates(projInst, &*builder.getInsertionPoint())) {
562+
if (domTree->properlyDominates(projInst, ip)) {
561563
cachedProj = projInst;
562564
return projInst;
563565
}
@@ -580,7 +582,7 @@ SILValue DestroyHoisting::createAddress(unsigned locIdx, SILBuilder &builder) {
580582
newProj = projBuilder.createTupleElementAddr(TEA->getLoc(), baseAddr,
581583
TEA->getFieldNo(), TEA->getType());
582584
}
583-
assert(domTree->properlyDominates(newProj, &*builder.getInsertionPoint()) &&
585+
assert(domTree->properlyDominates(newProj, ip) &&
584586
"new projection does not dominate insert point");
585587
// We need to remember the new projection instruction because in tailMerging
586588
// we might call locations.getLocationIdx() on such a new instruction.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %target-swift-frontend -O %s -emit-sil -o /dev/null
2+
3+
public struct S {
4+
let args: [Substring]
5+
let arg: Substring
6+
7+
enum Error: Swift.Error {
8+
case Case
9+
}
10+
11+
public init(arg: String) throws {
12+
args = arg.split(separator: "\n")
13+
guard args.count > 0 else { throw Error.Case }
14+
15+
let parts = args[0].split(separator: " ")
16+
guard parts.count > 2 else { throw Error.Case }
17+
18+
self.arg = parts[1]
19+
}
20+
}
21+

0 commit comments

Comments
 (0)