@@ -332,7 +332,7 @@ CastOptimizer::optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast) {
332332 ->getImplementationType ()
333333 ->getCanonicalType ();
334334 Tmp = Builder.createAllocStack (Loc,
335- SILType::getPrimitiveObjectType (OptionalTy));
335+ F-> getLoweredType (OptionalTy));
336336 outOptionalParam = Tmp;
337337 } else {
338338 outOptionalParam = Dest;
@@ -446,10 +446,11 @@ CastOptimizer::optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast) {
446446
447447static bool canOptimizeCast (const swift::Type &BridgedTargetTy,
448448 swift::SILFunctionConventions &substConv,
449- TypeExpansionContext context) {
449+ const SILFunction *F) {
450+ auto context = F->getTypeExpansionContext ();
451+
450452 // DestTy is the type which we want to convert to
451- SILType DestTy =
452- SILType::getPrimitiveObjectType (BridgedTargetTy->getCanonicalType ());
453+ SILType DestTy = F->getLoweredType (BridgedTargetTy->getCanonicalType ());
453454 // ConvTy is the return type of the _bridgeToObjectiveCImpl()
454455 auto ConvTy = substConv.getSILResultType (context).getObjectType ();
455456 if (ConvTy == DestTy) {
@@ -652,8 +653,7 @@ CastOptimizer::optimizeBridgedSwiftToObjCCast(SILDynamicCastInst dynamicCast) {
652653
653654 // Check that this is a case that the authors of this code thought it could
654655 // handle.
655- if (!canOptimizeCast (BridgedTargetTy, substConv,
656- F->getTypeExpansionContext ())) {
656+ if (!canOptimizeCast (BridgedTargetTy, substConv, F)) {
657657 return nullptr ;
658658 }
659659
0 commit comments