IRGen: fix how metadata is loaded for fast class casting

Pass the correct type to `emitHeapMetadataRefForHeapObject()`.
Fixes a runtime crash in case a class protocol is cast to a final swift class, where the actual object is an ObjectiveC class instance.

rdar://99626888
This commit is contained in:
Erik Eckstein
2022-09-21 10:36:14 +02:00
parent d015505090
commit 2527d3765e
3 changed files with 7 additions and 3 deletions

View File

@@ -1108,7 +1108,7 @@ llvm::Value *irgen::emitFastClassCastIfPossible(IRGenFunction &IGF,
// Load the isa pointer.
llvm::Value *objMetadata = emitHeapMetadataRefForHeapObject(IGF, instance,
targetFormalType, GenericSignature(), /*suppress cast*/ true);
sourceFormalType, GenericSignature(), /*suppress cast*/ true);
llvm::Value *rhs = IGF.Builder.CreateBitCast(objMetadata, IGF.IGM.Int8PtrTy);
// return isa_ptr == metadata_ptr ? instance : nullptr