mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user