Skip to content

Commit 050593f

Browse files
authored
[Coverage] Handle CoroutineSuspendExpr correctly (#88898)
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).
1 parent 00179e9 commit 050593f

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

clang/lib/CodeGen/CoverageMappingGen.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,10 @@ struct CounterCoverageMappingBuilder
14391439
terminateRegion(S);
14401440
}
14411441

1442+
void VisitCoroutineSuspendExpr(const CoroutineSuspendExpr *E) {
1443+
Visit(E->getOperand());
1444+
}
1445+
14421446
void VisitCXXThrowExpr(const CXXThrowExpr *E) {
14431447
extendRegion(E);
14441448
if (E->getSubExpr())

clang/test/CoverageMapping/coroutine.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct std::coroutine_traits<int, int> {
3232
suspend_always final_suspend() noexcept;
3333
void unhandled_exception() noexcept;
3434
void return_value(int);
35+
suspend_always yield_value(int);
3536
};
3637
};
3738

@@ -45,3 +46,21 @@ int f1(int x) { // CHECK-NEXT: File 0, [[@LINE]]:15 -> [[@LINE+8]]:2 = #0
4546
} // CHECK-NEXT: File 0, [[@LINE-2]]:10 -> [[@LINE]]:4 = (#0 - #1)
4647
co_return x; // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:4 -> [[@LINE]]:3 = #1
4748
} // CHECK-NEXT: File 0, [[@LINE-1]]:3 -> [[@LINE-1]]:14 = #1
49+
50+
// CHECK-LABEL: _Z2f2i:
51+
// CHECK-NEXT: File 0, [[@LINE+1]]:15 -> [[@LINE+15]]:2 = #0
52+
int f2(int x) {
53+
// CHECK-NEXT: File 0, [[@LINE+5]]:13 -> [[@LINE+5]]:18 = #0
54+
// CHECK-NEXT: Branch,File 0, [[@LINE+4]]:13 -> [[@LINE+4]]:18 = #1, (#0 - #1)
55+
// CHECK-NEXT: Gap,File 0, [[@LINE+3]]:20 -> [[@LINE+3]]:21 = #1
56+
// CHECK-NEXT: File 0, [[@LINE+2]]:21 -> [[@LINE+2]]:37 = #1
57+
// CHECK-NEXT: File 0, [[@LINE+1]]:40 -> [[@LINE+1]]:56 = (#0 - #1)
58+
co_await (x > 0 ? suspend_always{} : suspend_always{});
59+
// CHECK-NEXT: File 0, [[@LINE+5]]:12 -> [[@LINE+5]]:17 = #0
60+
// CHECK-NEXT: Branch,File 0, [[@LINE+4]]:12 -> [[@LINE+4]]:17 = #2, (#0 - #2)
61+
// CHECK-NEXT: Gap,File 0, [[@LINE+3]]:19 -> [[@LINE+3]]:20 = #2
62+
// CHECK-NEXT: File 0, [[@LINE+2]]:20 -> [[@LINE+2]]:21 = #2
63+
// CHECK-NEXT: File 0, [[@LINE+1]]:24 -> [[@LINE+1]]:25 = (#0 - #2)
64+
co_yield x > 0 ? 1 : 2;
65+
co_return 0;
66+
}

0 commit comments

Comments
 (0)