diff options
author | Hana Dusíková <hanicka@hanicka.net> | 2024-01-10 11:01:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-10 11:01:23 +0100 |
commit | a26cc759ae5a8018e2c328cf53173992340b995a (patch) | |
tree | cb6e6b063ae053351f695594991ef2c1b32bb2ca /clang/lib/CodeGen/CoverageMappingGen.cpp | |
parent | e22cb93890c33e21534338e4f2ea5ce640c78b77 (diff) | |
download | llvm-a26cc759ae5a8018e2c328cf53173992340b995a.zip llvm-a26cc759ae5a8018e2c328cf53173992340b995a.tar.gz llvm-a26cc759ae5a8018e2c328cf53173992340b995a.tar.bz2 |
[clang][coverage] Fix "if constexpr" and "if consteval" coverage report (#77214)
Replace the discarded statement by an empty compound statement so we can keep track of the
whole source range we need to skip in coverage
Fixes #54419
Diffstat (limited to 'clang/lib/CodeGen/CoverageMappingGen.cpp')
-rw-r--r-- | clang/lib/CodeGen/CoverageMappingGen.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp index bf22738..b245abd 100644 --- a/clang/lib/CodeGen/CoverageMappingGen.cpp +++ b/clang/lib/CodeGen/CoverageMappingGen.cpp @@ -1712,7 +1712,11 @@ struct CounterCoverageMappingBuilder extendRegion(S->getCond()); Counter ParentCount = getRegion().getCounter(); - Counter ThenCount = getRegionCounter(S); + + // If this is "if !consteval" the then-branch will never be taken, we don't + // need to change counter + Counter ThenCount = + S->isNegatedConsteval() ? ParentCount : getRegionCounter(S); if (!S->isConsteval()) { // Emitting a counter for the condition makes it easier to interpret the @@ -1729,7 +1733,12 @@ struct CounterCoverageMappingBuilder extendRegion(S->getThen()); Counter OutCount = propagateCounts(ThenCount, S->getThen()); - Counter ElseCount = subtractCounters(ParentCount, ThenCount); + // If this is "if consteval" the else-branch will never be taken, we don't + // need to change counter + Counter ElseCount = S->isNonNegatedConsteval() + ? ParentCount + : subtractCounters(ParentCount, ThenCount); + if (const Stmt *Else = S->getElse()) { bool ThenHasTerminateStmt = HasTerminateStmt; HasTerminateStmt = false; |