diff options
author | Vedant Kumar <vsk@apple.com> | 2019-11-21 14:17:04 -0800 |
---|---|---|
committer | Vedant Kumar <vsk@apple.com> | 2019-12-03 12:35:54 -0800 |
commit | 859bf4d2bea2404bd2eac92451f2db4371ec6eb4 (patch) | |
tree | b27618c806fb6fbbac6b44269e26ff7cd207de66 /clang/docs/SourceBasedCodeCoverage.rst | |
parent | bf830b01a21e6ff2f44c17be4ad4ee897465a677 (diff) | |
download | bcm5719-llvm-859bf4d2bea2404bd2eac92451f2db4371ec6eb4.tar.gz bcm5719-llvm-859bf4d2bea2404bd2eac92451f2db4371ec6eb4.zip |
[Coverage] Emit a gap region to cover switch bodies
Emit a gap region beginning where the switch body begins. This sets line
execution counts in the areas between non-overlapping cases to 0.
This also removes some special handling of the first case in a switch:
these are now treated like any other case.
This does not resolve an outstanding issue with case statement regions
that do not end when a region is terminated. But it should address
llvm.org/PR44011.
Differential Revision: https://reviews.llvm.org/D70571
Diffstat (limited to 'clang/docs/SourceBasedCodeCoverage.rst')
-rw-r--r-- | clang/docs/SourceBasedCodeCoverage.rst | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/clang/docs/SourceBasedCodeCoverage.rst b/clang/docs/SourceBasedCodeCoverage.rst index 73197a57713..7e711819be3 100644 --- a/clang/docs/SourceBasedCodeCoverage.rst +++ b/clang/docs/SourceBasedCodeCoverage.rst @@ -302,3 +302,37 @@ Drawbacks and limitations If the call to ``may_throw()`` propagates an exception into ``f``, the code coverage tool may mark the ``return`` statement as executed even though it is not. A call to ``longjmp()`` can have similar effects. + +Clang implementation details +============================ + +This section may be of interest to those wishing to understand or improve +the clang code coverage implementation. + +Gap regions +----------- + +Gap regions are source regions with counts. A reporting tool cannot set a line +execution count to the count from a gap region unless that region is the only +one on a line. + +Gap regions are used to eliminate unnatural artifacts in coverage reports, such +as red "unexecuted" highlights present at the end of an otherwise covered line, +or blue "executed" highlights present at the start of a line that is otherwise +not executed. + +Switch statements +----------------- + +The region mapping for a switch body consists of a gap region that covers the +entire body (starting from the '{' in 'switch (...) {', and terminating where the +last case ends). This gap region has a zero count: this causes "gap" areas in +between case statements, which contain no executable code, to appear uncovered. + +When a switch case is visited, the parent region is extended: if the parent +region has no start location, its start location becomes the start of the case. +This is used to support switch statements without a ``CompoundStmt`` body, in +which the switch body and the single case share a count. + +For switches with ``CompoundStmt`` bodies, a new region is created at the start +of each switch case. |