diff options
author | Justin Cady <desk@justincady.com> | 2025-03-21 11:59:01 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-21 11:59:01 -0400 |
commit | 954a3de7838a8c496ef1d1730127415b3e9786f9 (patch) | |
tree | 959eb8b142c182ace01a6c905ffe92fbf71dfb67 /clang/lib/CodeGen/CoverageMappingGen.cpp | |
parent | 79079c94699a4210bd500556d2864cbdf4a37e78 (diff) | |
download | llvm-954a3de7838a8c496ef1d1730127415b3e9786f9.zip llvm-954a3de7838a8c496ef1d1730127415b3e9786f9.tar.gz llvm-954a3de7838a8c496ef1d1730127415b3e9786f9.tar.bz2 |
Reland [Coverage] Fix region termination for GNU statement expressions (#132222)
Relands #130976 with adjustments to test requirements.
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.cpp | 8 |
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(); |