Skip to content

Commit eb8c9d9

Browse files
committed
[dynamic-cast] Hoist early bail out if the source objc type is address only.
This could probably be an error, but I am leaving it to preserve previous behavior. The reason I am hoisting this is that I am hoisting it before we potentially split a basic block. When we evaluate if we can early exit, we should never do work before we know that we will emit /something/.
1 parent e3acbd0 commit eb8c9d9

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

lib/SILOptimizer/Utils/CastOptimizer.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,15 @@ CastOptimizer::optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast) {
8989
}
9090
}
9191

92+
SILValue src = dynamicCast.getSource();
93+
// Check if we have a source type that is address only. We do not support that
94+
// today.
95+
if (src->getType().isAddressOnly(mod)) {
96+
return nullptr;
97+
}
98+
9299
SILInstruction *Inst = dynamicCast.getInstruction();
93100
bool isConditional = dynamicCast.isConditional();
94-
SILValue Src = dynamicCast.getSource();
95101
SILValue Dest = dynamicCast.getDest();
96102
CanType BridgedTargetTy = dynamicCast.getBridgedTargetType();
97103
SILBasicBlock *SuccessBB = dynamicCast.getSuccessBlock();
@@ -127,20 +133,13 @@ CastOptimizer::optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast) {
127133
// - then convert _ObjectiveCBridgeable._ObjectiveCType to
128134
// a Swift type using _forceBridgeFromObjectiveC.
129135

130-
if (!Src->getType().isLoadable(mod)) {
131-
// This code path is never reached in current test cases
132-
// If reached, we'd have to convert from an ObjC Any* to a loadable type
133-
// Should use check_addr / make a source we can actually load
134-
return nullptr;
135-
}
136-
137136
// Inline constructor.
138137
SILValue srcOp;
139138
SILInstruction *newI;
140139
std::tie(srcOp, newI) = [&]() -> std::pair<SILValue, SILInstruction *> {
141140
// Generate a load for the source argument.
142141
SILValue load =
143-
Builder.createLoad(Loc, Src, LoadOwnershipQualifier::Unqualified);
142+
Builder.createLoad(Loc, src, LoadOwnershipQualifier::Unqualified);
144143

145144
// If type of the source and the expected ObjC type are equal, there is no
146145
// need to generate the conversion from ObjCTy to

0 commit comments

Comments
 (0)