Skip to content

Commit 502522b

Browse files
authored
Merge pull request #42286 from compnerd/SR-16112
2 parents fc13d4e + 52d39f8 commit 502522b

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lib/IRGen/GenCast.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "llvm/IR/Module.h"
3131

3232
#include "swift/AST/ExistentialLayout.h"
33+
#include "swift/AST/IRGenOptions.h"
3334
#include "swift/SIL/DynamicCasts.h"
3435
#include "swift/SIL/SILInstruction.h"
3536
#include "swift/SIL/SILModule.h"
@@ -1061,8 +1062,8 @@ llvm::Value *irgen::emitFastClassCastIfPossible(IRGenFunction &IGF,
10611062
llvm::Value *instance,
10621063
CanType sourceFormalType,
10631064
CanType targetFormalType) {
1064-
if (!doesCastPreserveOwnershipForTypes(IGF.IGM.getSILModule(), sourceFormalType,
1065-
targetFormalType)) {
1065+
if (!doesCastPreserveOwnershipForTypes(IGF.IGM.getSILModule(),
1066+
sourceFormalType, targetFormalType)) {
10661067
return nullptr;
10671068
}
10681069

@@ -1089,6 +1090,17 @@ llvm::Value *irgen::emitFastClassCastIfPossible(IRGenFunction &IGF,
10891090

10901091
// Get the metadata pointer of the destination class type.
10911092
llvm::Value *destMetadata = IGF.IGM.getAddrOfTypeMetadata(targetFormalType);
1093+
if (IGF.IGM.IRGen.Opts.LazyInitializeClassMetadata) {
1094+
llvm::Function *accessor =
1095+
IGF.IGM.getAddrOfTypeMetadataAccessFunction(targetFormalType,
1096+
NotForDefinition);
1097+
auto request = DynamicMetadataRequest(MetadataState::Complete);
1098+
// We know that we are not in a gneric class context, so we can safely
1099+
// determine that the call here does not need to take that into account.
1100+
auto response =
1101+
IGF.emitGenericTypeMetadataAccessFunctionCall(accessor, {}, request);
1102+
destMetadata = response.getMetadata();
1103+
}
10921104
llvm::Value *lhs = IGF.Builder.CreateBitCast(destMetadata, IGF.IGM.Int8PtrTy);
10931105

10941106
// Load the isa pointer.

0 commit comments

Comments
 (0)