Skip to content

Commit 25e6e96

Browse files
committed
[Profiler] Avoid crashing on redundant break in repeat-while
Treat subtracting zero as a no-op, avoiding the assertion guarding against creating negative counters.
1 parent 6f64a4e commit 25e6e96

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/SIL/IR/SILProfiler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,9 @@ struct CoverageMapping : public ASTWalker {
907907

908908
/// Subtract \c Expr from \c Node's counter.
909909
void subtractFromCounter(ASTNode Node, CounterExpr Expr) {
910+
if (Expr.isZero())
911+
return;
912+
910913
auto Counter = getCounter(Node);
911914
assert(!Counter.isZero() && "Cannot create a negative counter");
912915
assignCounter(Node,

test/Profiler/coverage_while.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,12 @@ func hoo() { // CHECK-NEXT: [[@LINE]]:12 -> [[@LINE+5]]:2 : 0
130130
i += 1 // CHECK-NEXT: [[@LINE-1]]:18 -> [[@LINE+1]]:4 : 1
131131
} // CHECK-NEXT: [[@LINE]]:4 -> [[@LINE+1]]:2 : 0
132132
}
133+
134+
// CHECK-LABEL: sil_coverage_map {{.*}}// coverage_while.ioo
135+
func ioo() { // CHECK-NEXT: [[@LINE]]:12 -> [[@LINE+6]]:2 : 0
136+
repeat { // CHECK-NEXT: [[@LINE]]:10 -> [[@LINE+3]]:4 : 1
137+
break // CHECK-NEXT: [[@LINE+1]]:5 -> [[@LINE+1]]:10 : zero
138+
break // FIXME: This next region seems wrong, we exit the loop the same number of times we enter (rdar://118472537).
139+
} while true // CHECK-NEXT: [[@LINE]]:4 -> [[@LINE+2]]:2 : (0 - 1)
140+
// CHECK-NEXT: [[@LINE-1]]:11 -> [[@LINE-1]]:15 : zero
141+
} // CHECK-NEXT: }

0 commit comments

Comments
 (0)