From 025639bc396f1e0d2ead279c5f345cb381733f16 Mon Sep 17 00:00:00 2001 From: Justin Cady Date: Mon, 19 May 2025 15:49:26 -0400 Subject: [Coverage] Fix mapping for do-while loops with terminating statements (#139777) The current region mapping for do-while loops that contain statements such as break or continue results in inaccurate line coverage reports for the line following the loop. This change handles terminating statements the same way that other loop constructs do, correcting the region mapping for accurate reports. It also fixes a fragile test relying on exact line numbers. Fixes #139122 --- clang/lib/CodeGen/CoverageMappingGen.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'clang/lib/CodeGen/CoverageMappingGen.cpp') diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp index 73811d1..6170dc7 100644 --- a/clang/lib/CodeGen/CoverageMappingGen.cpp +++ b/clang/lib/CodeGen/CoverageMappingGen.cpp @@ -1703,14 +1703,13 @@ struct CounterCoverageMappingBuilder if (!IsCounterEqual(OutCount, ParentCount)) { pushRegion(OutCount); GapRegionCounter = OutCount; + if (BodyHasTerminateStmt) + HasTerminateStmt = true; } // Create Branch Region around condition. if (!llvm::EnableSingleByteCoverage) createBranchRegion(S->getCond(), BodyCount, BranchCount.Skipped); - - if (BodyHasTerminateStmt) - HasTerminateStmt = true; } void VisitForStmt(const ForStmt *S) { -- cgit v1.1