Don't "finalize" the empty-array singleton.

Array literals only need to be finalized, if the array is really allocated.
In case of zero elements, no allocation is done, but the empty-array singleton is used.
"Finalization" means to emit an end_cow_mutation instruction on the array.
As the empty-array singleton is a read-only and shared object, it's not legal to do a end_cow_mutation on it.
This commit is contained in:
Erik Eckstein
2020-07-03 15:29:01 +02:00
parent 5f6f46fc5d
commit 79913b9595
5 changed files with 24 additions and 16 deletions

View File

@@ -540,13 +540,15 @@ static SILValue emitCodeForConstantArray(ArrayRef<SILValue> elements,
assert(arrayAllocateFun);
SILFunction *arrayFinalizeFun = nullptr;
if (FuncDecl *arrayFinalizeDecl = astContext.getFinalizeUninitializedArray()) {
std::string finalizeMangledName =
SILDeclRef(arrayFinalizeDecl, SILDeclRef::Kind::Func).mangle();
arrayFinalizeFun =
module.findFunction(finalizeMangledName, SILLinkage::SharedExternal);
assert(arrayFinalizeFun);
module.linkFunction(arrayFinalizeFun);
if (numElements != 0) {
if (FuncDecl *arrayFinalizeDecl = astContext.getFinalizeUninitializedArray()) {
std::string finalizeMangledName =
SILDeclRef(arrayFinalizeDecl, SILDeclRef::Kind::Func).mangle();
arrayFinalizeFun =
module.findFunction(finalizeMangledName, SILLinkage::SharedExternal);
assert(arrayFinalizeFun);
module.linkFunction(arrayFinalizeFun);
}
}
// Call the _allocateUninitializedArray function with numElementsSIL. The