Skip to content

Commit 842b3c7

Browse files
committed
[cast-optimizer] Use a stricter pre-condition
Fixes a compiler crasher reported in rdar://21635259. Swift SVN r30517
1 parent 4a3b5ba commit 842b3c7

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

lib/SILPasses/Utils/Local.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1596,7 +1596,10 @@ optimizeCheckedCastAddrBranchInst(CheckedCastAddrBranchInst *Inst) {
15961596
MI = dyn_cast<MetatypeInst>(Src);
15971597

15981598
if (MI) {
1599-
if (SuccessBB->getSinglePredecessor()) {
1599+
if (SuccessBB->getSinglePredecessor()
1600+
&& canUseScalarCheckedCastInstructions(Inst->getModule(),
1601+
MI->getType().getSwiftRValueType(),
1602+
Dest.getType().getObjectType().getSwiftRValueType())) {
16001603
SILBuilderWithScope<1> B(Inst);
16011604
auto NewI = B.createCheckedCastBranch(
16021605
Loc, false /*isExact*/, SILValue(MI, 0),

test/SILPasses/cast_folding.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,29 @@ public func callForGenericCC(c: CC) {
751751
callFoo(c)
752752
}
753753

754+
// Check that this conversion does not crash a compiler.
755+
@inline(never)
756+
public func test34() {
757+
if let _ = A.self as? P {
758+
print("A: dice")
759+
} else {
760+
print("A: no dice")
761+
}
762+
}
763+
764+
765+
// Check that this conversion does not crash a compiler.
766+
@inline(never)
767+
public func test35() {
768+
if let _ = X.self as? P {
769+
print("X: dice")
770+
} else {
771+
print("X: no dice")
772+
}
773+
}
774+
775+
776+
754777
print("test0=\(test0())")
755778

756779
print("test1=\(test1())")

0 commit comments

Comments
 (0)