[IRGen] Erase nonoverride descriptor on emission.

Previously, emitting the descriptor for a nonoverride method always
simply emitted, even if it had previously been emitted.  That was not a
problem before, but is now that class type context descriptors can be
reemitted upon encountering metadata prespecializations.

Here, the behavior is changed to delete the old definition before
emitting the new definition.
This commit is contained in:
Nate Chandler
2020-08-13 16:03:04 -07:00
parent c25c180c08
commit 3ad2777a68

View File

@@ -300,6 +300,10 @@ static void buildMethodDescriptorFields(IRGenModule &IGM,
void IRGenModule::emitNonoverriddenMethodDescriptor(const SILVTable *VTable,
SILDeclRef declRef) {
auto entity = LinkEntity::forMethodDescriptor(declRef);
auto *var = cast<llvm::GlobalVariable>(getAddrOfLLVMVariable(entity, ConstantInit(), DebugTypeInfo()));
var->setInitializer(nullptr);
ConstantInitBuilder ib(*this);
ConstantStructBuilder sb(ib.beginStruct(MethodDescriptorStructTy));
@@ -308,7 +312,6 @@ void IRGenModule::emitNonoverriddenMethodDescriptor(const SILVTable *VTable,
auto init = sb.finishAndCreateFuture();
auto entity = LinkEntity::forMethodDescriptor(declRef);
getAddrOfLLVMVariable(entity, init, DebugTypeInfo());
}