aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CoverageMappingGen.cpp
diff options
context:
space:
mode:
authorJustin Cady <desk@justincady.com>2025-03-19 16:22:26 -0400
committerGitHub <noreply@github.com>2025-03-19 16:22:26 -0400
commit0827e3aae6eb69c2a6fa842ffa780881feb45b5d (patch)
tree27baaa02cdc9c0716bf7df5d31fc38801a1630f3 /clang/lib/CodeGen/CoverageMappingGen.cpp
parentbdca412681d668231aed0cb58b450713e8f9b01a (diff)
downloadllvm-0827e3aae6eb69c2a6fa842ffa780881feb45b5d.zip
llvm-0827e3aae6eb69c2a6fa842ffa780881feb45b5d.tar.gz
llvm-0827e3aae6eb69c2a6fa842ffa780881feb45b5d.tar.bz2
[Coverage] Fix region termination for GNU statement expressions (#130976)
Calls to __noreturn__ functions result in region termination for coverage mapping. But this creates incorrect coverage results when __noreturn__ functions (or other constructs that result in region termination) occur within [GNU statement expressions][1]. In this scenario an extra gap region is introduced within VisitStmt, such that if the following line does not introduce a new region it is unconditionally counted as uncovered. This change adjusts the mapping such that terminate statements within statement expressions do not propagate that termination state after the statement expression is processed. [1]: https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html Fixes #124296
Diffstat (limited to 'clang/lib/CodeGen/CoverageMappingGen.cpp')
-rw-r--r--clang/lib/CodeGen/CoverageMappingGen.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp
index f091577..73811d1 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1505,6 +1505,14 @@ struct CounterCoverageMappingBuilder
handleFileExit(getEnd(S));
}
+ void VisitStmtExpr(const StmtExpr *E) {
+ Visit(E->getSubStmt());
+ // Any region termination (such as a noreturn CallExpr) within the statement
+ // expression has been handled by visiting the sub-statement. The visitor
+ // cannot be at a terminate statement leaving the statement expression.
+ HasTerminateStmt = false;
+ }
+
void VisitDecl(const Decl *D) {
Stmt *Body = D->getBody();