Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions lib/SILOptimizer/Utils/CastOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,7 @@ CastOptimizer::optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast) {
OptionalTy = OptionalType::get(Dest->getType().getASTType())
->getImplementationType()
->getCanonicalType();
Tmp = Builder.createAllocStack(Loc,
SILType::getPrimitiveObjectType(OptionalTy));
Tmp = Builder.createAllocStack(Loc, F->getLoweredType(OptionalTy));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I bet this code was written before Swift 3.1, in which case the getLoweredType() call was a no-op (optional payloads used to be unlowered).

outOptionalParam = Tmp;
} else {
outOptionalParam = Dest;
Expand Down Expand Up @@ -446,10 +445,11 @@ CastOptimizer::optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast) {

static bool canOptimizeCast(const swift::Type &BridgedTargetTy,
swift::SILFunctionConventions &substConv,
TypeExpansionContext context) {
const SILFunction *F) {
auto context = F->getTypeExpansionContext();

// DestTy is the type which we want to convert to
SILType DestTy =
SILType::getPrimitiveObjectType(BridgedTargetTy->getCanonicalType());
SILType DestTy = F->getLoweredType(BridgedTargetTy->getCanonicalType());
// ConvTy is the return type of the _bridgeToObjectiveCImpl()
auto ConvTy = substConv.getSILResultType(context).getObjectType();
if (ConvTy == DestTy) {
Expand Down Expand Up @@ -652,8 +652,7 @@ CastOptimizer::optimizeBridgedSwiftToObjCCast(SILDynamicCastInst dynamicCast) {

// Check that this is a case that the authors of this code thought it could
// handle.
if (!canOptimizeCast(BridgedTargetTy, substConv,
F->getTypeExpansionContext())) {
if (!canOptimizeCast(BridgedTargetTy, substConv, F)) {
return nullptr;
}

Expand Down
9 changes: 9 additions & 0 deletions validation-test/SILOptimizer/rdar162922634.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: %target-swift-frontend -O -emit-sil -verify %s

// REQUIRES: objc_interop

import Foundation

func f(_ x: [AnyHashable]) -> [NSObject.Type]? {
return x as? [NSObject.Type]
}