Skip to content

[Profiler] Avoid crashing on redundant break in repeat-while #70121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/SIL/IR/SILProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,9 @@ struct CoverageMapping : public ASTWalker {

/// Subtract \c Expr from \c Node's counter.
void subtractFromCounter(ASTNode Node, CounterExpr Expr) {
if (Expr.isZero())
return;

auto Counter = getCounter(Node);
assert(!Counter.isZero() && "Cannot create a negative counter");
assignCounter(Node,
Expand Down
9 changes: 9 additions & 0 deletions test/Profiler/coverage_while.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,12 @@ func hoo() { // CHECK-NEXT: [[@LINE]]:12 -> [[@LINE+5]]:2 : 0
i += 1 // CHECK-NEXT: [[@LINE-1]]:18 -> [[@LINE+1]]:4 : 1
} // CHECK-NEXT: [[@LINE]]:4 -> [[@LINE+1]]:2 : 0
}

// CHECK-LABEL: sil_coverage_map {{.*}}// coverage_while.ioo
func ioo() { // CHECK-NEXT: [[@LINE]]:12 -> [[@LINE+6]]:2 : 0
repeat { // CHECK-NEXT: [[@LINE]]:10 -> [[@LINE+3]]:4 : 1
break // CHECK-NEXT: [[@LINE+1]]:5 -> [[@LINE+1]]:10 : zero
break // FIXME: This next region seems wrong, we exit the loop the same number of times we enter (rdar://118472537).
} while true // CHECK-NEXT: [[@LINE]]:4 -> [[@LINE+2]]:2 : (0 - 1)
// CHECK-NEXT: [[@LINE-1]]:11 -> [[@LINE-1]]:15 : zero
} // CHECK-NEXT: }