COWArrayOpts: fix a mis-compile related to owned function arguments

COWArrayOpts wrongly assumed that an 'owned' argument is released in the function.

https://bugs.swift.org/browse/SR-12440
rdar://problem/62201043
This commit is contained in:
Erik Eckstein
2020-05-04 17:30:25 +02:00
parent 717eeb912d
commit 54e54ae4fe
2 changed files with 23 additions and 19 deletions

View File

@@ -99,25 +99,6 @@ static bool isRelease(SILInstruction *Inst, SILValue RetainedValue,
return true;
}
if (auto *AI = dyn_cast<ApplyInst>(Inst)) {
if (auto *F = AI->getReferencedFunctionOrNull()) {
auto Params = F->getLoweredFunctionType()->getParameters();
auto Args = AI->getArguments();
for (unsigned ArgIdx = 0, ArgEnd = Params.size(); ArgIdx != ArgEnd;
++ArgIdx) {
if (MatchedReleases.count(&AI->getArgumentRef(ArgIdx)))
continue;
if (!areArraysEqual(RCIA, Args[ArgIdx], RetainedValue, ArrayAddress))
continue;
ParameterConvention P = Params[ArgIdx].getConvention();
if (P == ParameterConvention::Direct_Owned) {
LLVM_DEBUG(llvm::dbgs() << " matching with release " << *Inst);
MatchedReleases.insert(&AI->getArgumentRef(ArgIdx));
return true;
}
}
}
}
LLVM_DEBUG(llvm::dbgs() << " not a matching release " << *Inst);
return false;
}