Skip to content

Commit 55a6b34

Browse files
committed
[IRGen] RuntimeMetadata: Reference type descriptors indirectly when required
Type descriptors cannot always be referenced directly (i.e. when a type is declared in a different module), so let's use `getAddrOfLLVMVariableOrGOTEquivalent` facility that knows how to handle that correctly. Resolves: rdar://problem/103878515
1 parent 0d082df commit 55a6b34

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

include/swift/ABI/Metadata.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4759,7 +4759,10 @@ class RuntimeDiscoverableAttributeRecord
47594759
uint32_t flags;
47604760

47614761
/// The nominal type that describes the attribute.
4762-
TargetSignedContextPointer<Runtime, TargetTypeContextDescriptor> Attribute;
4762+
TargetRelativeIndirectablePointer<Runtime,
4763+
TargetTypeContextDescriptor<Runtime>,
4764+
/*nullable*/ false>
4765+
Attribute;
47634766

47644767
/// The number of types this attribute is associated with.
47654768
uint32_t numEntries;

lib/IRGen/GenDecl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4449,8 +4449,8 @@ void IRGenModule::emitRuntimeDiscoverableAttributes(
44494449
B.addInt32(0);
44504450

44514451
// Attribute metadata descriptor
4452-
B.addRelativeAddress(
4453-
getAddrOfTypeContextDescriptor(attrType, RequireMetadata));
4452+
B.addRelativeAddress(getAddrOfLLVMVariableOrGOTEquivalent(
4453+
LinkEntity::forNominalTypeDescriptor(attrType)));
44544454

44554455
// Number of types it's attached to.
44564456
B.addInt32(attachedTo.size());

test/IRGen/runtime_attributes.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585

8686
// CHECK: @"$s3RAD6IgnoreVHa" = internal constant
8787
// CHECK-SAME: i32 0
88-
// CHECK-SAME: @"$s3RAD6IgnoreVMn"
88+
// CHECK-SAME: %swift.type_descriptor** @"got.$s3RAD6IgnoreVMn"
8989
// CHECK-SAME: i32 5
9090
// CHECK-SAME: @"$s18runtime_attributes1AV5InnerC11extComputedSivpfa3RAD6IgnoreHF"
9191
// CHECK-SAME: @"$s18runtime_attributes16WithExternalAttrAaBVmvpfa3RAD6IgnoreHF"
@@ -96,7 +96,7 @@
9696

9797
// CHECK: @"$s3RAD13TestAmbiguityVHa" = internal constant
9898
// CHECK-SAME: i32 0
99-
// CHECK-SAME: @"$s3RAD13TestAmbiguityVMn"
99+
// CHECK-SAME: %swift.type_descriptor** @"got.$s3RAD13TestAmbiguityVMn"
100100
// CHECK-SAME: i32 6
101101
// CHECK-SAME: @"$s18runtime_attributes4testyySicvpfa3RAD13TestAmbiguityHF"
102102
// CHECK-SAME: @"$s18runtime_attributes4testyySScvpfa3RAD13TestAmbiguityHF"

0 commit comments

Comments
 (0)