Skip to content

Commit c26134f

Browse files
committed
PerformanceDiagnostics: correctly handle functions with multiple throws
This is a follow-up of #69300, which didn't handle function with multiple throws correctly. rdar://117857767
1 parent 3094e66 commit c26134f

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/SILOptimizer/Mandatory/PerformanceDiagnostics.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ bool PerformanceDiagnostics::visitFunction(SILFunction *function,
170170
if (isa<ThrowInst>(block.getTerminator()))
171171
continue;
172172

173+
// If a function has multiple throws, all throw-path branch to the single throw-block.
174+
if (SILBasicBlock *succ = block.getSingleSuccessorBlock()) {
175+
if (isa<ThrowInst>(succ->getTerminator()))
176+
continue;
177+
}
178+
173179
if (!neBlocks.isNonErrorHandling(&block))
174180
continue;
175181

test/SILOptimizer/performance-annotations.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ func testMemoryLayout() -> Int {
9292
}
9393

9494
class MyError : Error {}
95+
class MyError2 : Error {}
9596

9697
@_noLocks
9798
func errorExistential(_ b: Bool) throws -> Int {
@@ -101,6 +102,17 @@ func errorExistential(_ b: Bool) throws -> Int {
101102
throw MyError()
102103
}
103104

105+
@_noLocks
106+
func multipleThrows(_ b1: Bool, _ b2: Bool) throws -> Int {
107+
if b1 {
108+
throw MyError()
109+
}
110+
if b2 {
111+
throw MyError2()
112+
}
113+
return 28
114+
}
115+
104116
@_noLocks
105117
func testCatch(_ b: Bool) throws -> Int? {
106118
do {

0 commit comments

Comments
 (0)