@@ -331,8 +331,7 @@ CastOptimizer::optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast) {
331331 OptionalTy = OptionalType::get (Dest->getType ().getASTType ())
332332 ->getImplementationType ()
333333 ->getCanonicalType ();
334- Tmp = Builder.createAllocStack (Loc,
335- SILType::getPrimitiveObjectType (OptionalTy));
334+ Tmp = Builder.createAllocStack (Loc, F->getLoweredType (OptionalTy));
336335 outOptionalParam = Tmp;
337336 } else {
338337 outOptionalParam = Dest;
@@ -446,10 +445,11 @@ CastOptimizer::optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast) {
446445
447446static bool canOptimizeCast (const swift::Type &BridgedTargetTy,
448447 swift::SILFunctionConventions &substConv,
449- TypeExpansionContext context) {
448+ const SILFunction *F) {
449+ auto context = F->getTypeExpansionContext ();
450+
450451 // DestTy is the type which we want to convert to
451- SILType DestTy =
452- SILType::getPrimitiveObjectType (BridgedTargetTy->getCanonicalType ());
452+ SILType DestTy = F->getLoweredType (BridgedTargetTy->getCanonicalType ());
453453 // ConvTy is the return type of the _bridgeToObjectiveCImpl()
454454 auto ConvTy = substConv.getSILResultType (context).getObjectType ();
455455 if (ConvTy == DestTy) {
@@ -652,8 +652,7 @@ CastOptimizer::optimizeBridgedSwiftToObjCCast(SILDynamicCastInst dynamicCast) {
652652
653653 // Check that this is a case that the authors of this code thought it could
654654 // handle.
655- if (!canOptimizeCast (BridgedTargetTy, substConv,
656- F->getTypeExpansionContext ())) {
655+ if (!canOptimizeCast (BridgedTargetTy, substConv, F)) {
657656 return nullptr ;
658657 }
659658
0 commit comments