@@ -2561,12 +2561,27 @@ static llvm::Function *emitObjCMetadataUpdateFunction(IRGenModule &IGM,
25612561 Explosion params = IGF.collectParameters ();
25622562 (void ) params.claimAll ();
25632563
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+
25702585 IGF.Builder .CreateRet (
25712586 IGF.Builder .CreateBitCast (metadata,
25722587 IGM.ObjCClassPtrTy ));
0 commit comments