Skip to content

Commit 3aa3d8e

Browse files
committed
SimplifyCheckedCast: only simplify if source and destination address types match
Fixes a crash when creating a copy_addr with mismtaching types. rdar://128195403
1 parent 4debfad commit 3aa3d8e

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifyCheckedCast.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ extension CheckedCastAddrBranchInst : OnoneSimplifyable {
1818
return
1919
}
2020
if castWillSucceed {
21-
replaceSuccess(context)
21+
// TODO: handle cases where the operand address types are different.
22+
if source.type == destination.type {
23+
replaceSuccess(context)
24+
}
2225
} else {
2326
replaceFailure(context)
2427
}

test/SILOptimizer/simplify_checked_cast_addr_br.sil

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,14 @@ bb2:
129129
unreachable
130130
}
131131

132+
// Check that we don't crash on this
133+
sil @success_but_different_operand_type : $@convention(thin) (@in D) -> @out X {
134+
bb0(%0 : $*X, %1 : $*D):
135+
checked_cast_addr_br copy_on_success D in %1 : $*D to X in %0 : $*X, bb1, bb2
136+
bb1:
137+
%r = tuple()
138+
return %r : $()
139+
bb2:
140+
unreachable
141+
}
142+

0 commit comments

Comments
 (0)