Skip to content

Commit

Permalink
[Coverage] Handle CoroutineSuspendExpr correctly (#88898)
Browse files Browse the repository at this point in the history
This avoids visiting `co_await` or `co_yield` operand 5 times (it is
repeated under transformed awaiter subexpression, and under
`await_ready`, `await_suspend`, and `await_resume` generated call
subexpressions).
  • Loading branch information
bolshakov-a authored May 15, 2024
1 parent 00179e9 commit 050593f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions clang/lib/CodeGen/CoverageMappingGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,10 @@ struct CounterCoverageMappingBuilder
terminateRegion(S);
}

void VisitCoroutineSuspendExpr(const CoroutineSuspendExpr *E) {
Visit(E->getOperand());
}

void VisitCXXThrowExpr(const CXXThrowExpr *E) {
extendRegion(E);
if (E->getSubExpr())
Expand Down
19 changes: 19 additions & 0 deletions clang/test/CoverageMapping/coroutine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct std::coroutine_traits<int, int> {
suspend_always final_suspend() noexcept;
void unhandled_exception() noexcept;
void return_value(int);
suspend_always yield_value(int);
};
};

Expand All @@ -45,3 +46,21 @@ int f1(int x) { // CHECK-NEXT: File 0, [[@LINE]]:15 -> [[@LINE+8]]:2 = #0
} // CHECK-NEXT: File 0, [[@LINE-2]]:10 -> [[@LINE]]:4 = (#0 - #1)
co_return x; // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:4 -> [[@LINE]]:3 = #1
} // CHECK-NEXT: File 0, [[@LINE-1]]:3 -> [[@LINE-1]]:14 = #1

// CHECK-LABEL: _Z2f2i:
// CHECK-NEXT: File 0, [[@LINE+1]]:15 -> [[@LINE+15]]:2 = #0
int f2(int x) {
// CHECK-NEXT: File 0, [[@LINE+5]]:13 -> [[@LINE+5]]:18 = #0
// CHECK-NEXT: Branch,File 0, [[@LINE+4]]:13 -> [[@LINE+4]]:18 = #1, (#0 - #1)
// CHECK-NEXT: Gap,File 0, [[@LINE+3]]:20 -> [[@LINE+3]]:21 = #1
// CHECK-NEXT: File 0, [[@LINE+2]]:21 -> [[@LINE+2]]:37 = #1
// CHECK-NEXT: File 0, [[@LINE+1]]:40 -> [[@LINE+1]]:56 = (#0 - #1)
co_await (x > 0 ? suspend_always{} : suspend_always{});
// CHECK-NEXT: File 0, [[@LINE+5]]:12 -> [[@LINE+5]]:17 = #0
// CHECK-NEXT: Branch,File 0, [[@LINE+4]]:12 -> [[@LINE+4]]:17 = #2, (#0 - #2)
// CHECK-NEXT: Gap,File 0, [[@LINE+3]]:19 -> [[@LINE+3]]:20 = #2
// CHECK-NEXT: File 0, [[@LINE+2]]:20 -> [[@LINE+2]]:21 = #2
// CHECK-NEXT: File 0, [[@LINE+1]]:24 -> [[@LINE+1]]:25 = (#0 - #2)
co_yield x > 0 ? 1 : 2;
co_return 0;
}

0 comments on commit 050593f

Please sign in to comment.