Skip to content

DestroyHoisting: fix a bug which creates invalid SIL #30610

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions lib/SILOptimizer/Transforms/DestroyHoisting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,15 +549,17 @@ SILValue DestroyHoisting::createAddress(unsigned locIdx, SILBuilder &builder) {
assert(!isa<BeginAccessInst>(loc->representativeValue) &&
"only a root location can be a begin_access");

SingleValueInstruction *&cachedProj = addressProjections[locIdx];
if (cachedProj)
return cachedProj;

if (!domTree)
domTree = DA->get(function);

SILInstruction *ip = &*builder.getInsertionPoint();

SingleValueInstruction *&cachedProj = addressProjections[locIdx];
if (cachedProj && domTree->properlyDominates(cachedProj, ip))
return cachedProj;

auto *projInst = cast<SingleValueInstruction>(loc->representativeValue);
if (domTree->properlyDominates(projInst, &*builder.getInsertionPoint())) {
if (domTree->properlyDominates(projInst, ip)) {
cachedProj = projInst;
return projInst;
}
Expand All @@ -580,7 +582,7 @@ SILValue DestroyHoisting::createAddress(unsigned locIdx, SILBuilder &builder) {
newProj = projBuilder.createTupleElementAddr(TEA->getLoc(), baseAddr,
TEA->getFieldNo(), TEA->getType());
}
assert(domTree->properlyDominates(newProj, &*builder.getInsertionPoint()) &&
assert(domTree->properlyDominates(newProj, ip) &&
"new projection does not dominate insert point");
// We need to remember the new projection instruction because in tailMerging
// we might call locations.getLocationIdx() on such a new instruction.
Expand Down
21 changes: 21 additions & 0 deletions test/SILOptimizer/destroy_hoisting_crash.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// RUN: %target-swift-frontend -O %s -emit-sil -o /dev/null

public struct S {
let args: [Substring]
let arg: Substring

enum Error: Swift.Error {
case Case
}

public init(arg: String) throws {
args = arg.split(separator: "\n")
guard args.count > 0 else { throw Error.Case }

let parts = args[0].split(separator: " ")
guard parts.count > 2 else { throw Error.Case }

self.arg = parts[1]
}
}