Skip to content

Commit aec5756

Browse files
Merge pull request #23626 from aschwaighofer/irgen_recover_metadata_from_objc_metadata
IRGen: Recover metadata from Objective-C metadata
2 parents da3468a + a90a6d8 commit aec5756

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/IRGen/GenProto.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,12 @@ bindParameterSource(SILParameterInfo param, unsigned paramIndex,
619619
llvm::Value *metadata = getParameter(paramIndex);
620620
IGF.bindLocalTypeDataFromTypeMetadata(paramType, IsInexact, metadata,
621621
MetadataState::Complete);
622+
} else if (metatype->getRepresentation() == MetatypeRepresentation::ObjC) {
623+
paramType = metatype.getInstanceType();
624+
llvm::Value *objcMetatype = getParameter(paramIndex);
625+
auto *metadata = emitObjCMetadataRefForMetadata(IGF, objcMetatype);
626+
IGF.bindLocalTypeDataFromTypeMetadata(paramType, IsInexact, metadata,
627+
MetadataState::Complete);
622628
}
623629
return;
624630
}

test/IRGen/objc_generic_class_metadata.sil

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,22 @@ entry(%0 : $Subclass, %1 : $NSDictionary):
9393
// CHECK: [[TMP:%.*]] = call swiftcc %swift.metadata_response @"$sSo12GenericClassCMa"([[INT]] 255)
9494
// CHECK: [[CLASS:%.*]] = extractvalue %swift.metadata_response [[TMP]], 0
9595
// CHECK: call swiftcc %swift.metadata_response @swift_getTupleTypeMetadata2([[INT]] %0, %swift.type* [[CLASS]], %swift.type* @"$sSiN", i8* null,
96+
97+
class K<T> {}
98+
99+
sil @$useMeta : $@convention(thin) <P> () -> ()
100+
101+
// CHECK-LABEL: define void @an_objc_method(i8*, i8*)
102+
// CHECK: [[C:%.*]] = bitcast i8* %0 to %objc_class*
103+
// CHECK: [[M:%.*]] = call %swift.type* @swift_getObjCClassMetadata(%objc_class* [[C]])
104+
// CHECK: [[M2:%.*]] = bitcast %swift.type* [[M]] to %swift.type**
105+
// CHECK: [[P:%.*]] = getelementptr inbounds %swift.type*, %swift.type** [[M2]]
106+
// CHECK: [[P2:%.*]] = load %swift.type*, %swift.type** [[P]]
107+
// CHECK: call swiftcc void @"$useMeta"(%swift.type* [[P2]])
108+
// CHECK: ret void
109+
sil @an_objc_method : $@convention(objc_method) <P> (@objc_metatype K<P>.Type) -> () {
110+
bb0(%0 : $@objc_metatype K<P>.Type):
111+
%2 = function_ref @$useMeta : $@convention(thin) <τ_0_0> () -> ()
112+
%3 = apply %2<P>() : $@convention(thin) <τ_0_0 > () -> ()
113+
return undef : $()
114+
}

0 commit comments

Comments
 (0)