Skip to content

Commit 509f905

Browse files
authored
Merge pull request #34977 from slavapestov/nonoverridden-descriptors
IRGen: Nonoverridden method descriptors should be true-const
2 parents a86a26c + 379d752 commit 509f905

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/IRGen/GenMeta.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,16 @@ static void buildMethodDescriptorFields(IRGenModule &IGM,
301301
void IRGenModule::emitNonoverriddenMethodDescriptor(const SILVTable *VTable,
302302
SILDeclRef declRef) {
303303
auto entity = LinkEntity::forMethodDescriptor(declRef);
304-
auto *var = cast<llvm::GlobalVariable>(getAddrOfLLVMVariable(entity, ConstantInit(), DebugTypeInfo()));
304+
auto *var = cast<llvm::GlobalVariable>(
305+
getAddrOfLLVMVariable(entity, ConstantInit(), DebugTypeInfo()));
305306
if (!var->isDeclaration()) {
306307
assert(IRGen.isLazilyReemittingNominalTypeDescriptor(VTable->getClass()));
307308
return;
308309
}
309310

311+
var->setConstant(true);
312+
setTrueConstGlobal(var);
313+
310314
ConstantInitBuilder ib(*this);
311315
ConstantStructBuilder sb(ib.beginStruct(MethodDescriptorStructTy));
312316

test/IRGen/vtable_non_overridden.sil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ sil_vtable InternalA {
2525
}
2626

2727
// -- we should still generate method descriptors for the elided methods
28-
// CHECK-LABEL: @"$s21vtable_non_overridden9InternalAC3fooyyFTq" =
29-
// CHECK-LABEL: @"$s21vtable_non_overridden9InternalAC3basyyFTq" =
28+
// CHECK-LABEL: @"$s21vtable_non_overridden9InternalAC3fooyyFTq" = hidden constant %swift.method_descriptor {{.*}} section "{{(__TEXT,__const|\.rodata|\.rdata)}}"
29+
// CHECK-LABEL: @"$s21vtable_non_overridden9InternalAC3basyyFTq" = hidden constant %swift.method_descriptor {{.*}} section "{{(__TEXT,__const|\.rodata|\.rdata)}}"
3030

3131
// -- only overridden entries in internal method descriptor table
3232
// CHECK-LABEL: @"$s21vtable_non_overridden9InternalACMn" =

0 commit comments

Comments
 (0)