@@ -2561,12 +2561,27 @@ static llvm::Function *emitObjCMetadataUpdateFunction(IRGenModule &IGM,
2561
2561
Explosion params = IGF.collectParameters ();
2562
2562
(void ) params.claimAll ();
2563
2563
2564
- // Just directly call our metadata accessor. This should actually
2565
- // return the same metadata; the Objective-C runtime enforces this.
2566
- auto type = D->getDeclaredType ()->getCanonicalType ();
2567
- auto *metadata = IGF.emitTypeMetadataRef (type,
2568
- MetadataState::Complete)
2569
- .getMetadata ();
2564
+ llvm::Value *metadata;
2565
+ if (D->getObjCImplementationDecl ()) {
2566
+ // This is an @objc @implementation class, so it has no metadata completion
2567
+ // function. We must do the completion function's work here, taking care to
2568
+ // fetch the address of the ObjC class without going through either runtime.
2569
+ metadata = IGM.getAddrOfObjCClass (D, NotForDefinition);
2570
+ auto loweredTy = IGM.getLoweredType (D->getDeclaredTypeInContext ());
2571
+
2572
+ IGF.emitInitializeFieldOffsetVector (loweredTy, metadata,
2573
+ /* isVWTMutable=*/ false ,
2574
+ /* collector=*/ nullptr );
2575
+ } else {
2576
+ // Just call our metadata accessor, which will cause the Swift runtime to
2577
+ // call the metadata completion function if there is one. This should
2578
+ // actually return the same metadata; the Objective-C runtime enforces this.
2579
+ auto type = D->getDeclaredType ()->getCanonicalType ();
2580
+ metadata = IGF.emitTypeMetadataRef (type,
2581
+ MetadataState::Complete)
2582
+ .getMetadata ();
2583
+ }
2584
+
2570
2585
IGF.Builder .CreateRet (
2571
2586
IGF.Builder .CreateBitCast (metadata,
2572
2587
IGM.ObjCClassPtrTy ));
0 commit comments