470 Commits

Author SHA1 Message Date
Roman Beliaev
653f81587f
[llvm-cov] Add FileID to MCDC records of the json code coverage export (#145236)
At the moment MCDC Record contains ExpandedFileID. If FileID !=
ExpandedFileID, the record's lines LineStart and LineEnd relate to the
`FileID` file, but the record doesn't contain this id. So we can't
distinguish multiple MCDC records with the same lines and columns, but
different FileIDs.

This adds FileID to MCDC records as it is done for regions and branches.
2025-07-08 09:56:57 -05:00
uthmanna
da5c442550
Reland "[llvm-cov] Export decision coverage to output json (#144335)" (#145325)
Tests fixed

This commit adds decision coverage counts derived from MC/DC test vector execution to the JSON output of llvm-cov, as discussed here: [Missing Decision Coverage (DC) in output json](https://discourse.llvm.org/t/missing-decision-coverage-dc-in-output-json/86783) with @evodius96
2025-06-24 10:41:13 -05:00
Alan Phipps
88d250729e
Revert "[llvm-cov] Export decision coverage to output json" (#144783)
Reverts llvm/llvm-project#144335

Need to resolve test failures
2025-06-18 14:33:59 -05:00
uthmanna
ab6beeca9c
[llvm-cov] Export decision coverage to output json (#144335)
This commit adds decision coverage counts derived from MC/DC test vector execution to the JSON output of llvm-cov, as
discussed here: [Missing Decision Coverage (DC) in output
json](https://discourse.llvm.org/t/missing-decision-coverage-dc-in-output-json/86783)
with @evodius96

---------

Co-authored-by: uthmanna <andre.uthmann@vector.com>
2025-06-18 14:00:10 -05:00
Fabian Meumertzheim
83f215b035
Reland "[llvm-cov] Add support for baseline coverage" (#144130)
When no profile is provided, but the new --empty-profile option is
specified, the export/report/show commands now emit coverage data
equivalent to that obtained from a profile with all zero counters
("baseline coverage").

This is useful for build systems (e.g. Bazel) that can track coverage
information for each build target, even those that are never linked into
tests and thus don't have runtime coverage data recorded. By merging in
baseline coverage, lines in files that aren't linked into tests are
correctly reported as uncovered.

Reland with fixes to `CoverageMappingTest.cpp`.

Reverts llvm/llvm-project#144121
2025-06-13 12:09:58 -07:00
Keith Smiley
65d88d31ea
Revert "[llvm-cov] Add support for baseline coverage" (#144121)
Reverts llvm/llvm-project#117910

```
/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/llvm/unittests/ProfileData/CoverageMappingTest.cpp
/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/llvm/unittests/ProfileData/CoverageMappingTest.cpp:281:28: error: 'std::reference_wrapper' may not intend to support class template argument deduction [-Werror,-Wctad-maybe-unsupported]
  281 |         std::make_optional(std::reference_wrapper(*ProfileReader));
      |                            ^
/usr/lib/gcc/ppc64le-redhat-linux/8/../../../../include/c++/8/bits/refwrap.h:289:11: note: add a deduction guide to suppress this warning
  289 |     class reference_wrapper
      |           ^
```
2025-06-13 10:04:45 -07:00
Fabian Meumertzheim
dc9e300f12
[llvm-cov] Add support for baseline coverage (#117910)
When no profile is provided, but the new --empty-profile option is
specifed, the export/report/show commands now emit coverage data
equivalent to that obtained from a profile with all zero counters
("baseline coverage").

This is useful for build systems (e.g. Bazel) that can track coverage
information for each build target, even those that are never linked into
tests and thus don't have runtime coverage data recorded. By merging in
baseline coverage, lines in files that aren't linked into tests are
correctly reported as uncovered.
2025-06-13 08:49:30 -07:00
Kazu Hirata
03f616eb3a
[llvm] Compare std::optional<T> to values directly (NFC) (#143340)
This patch transforms:

  X && *X == Y

to:

  X == Y

where X is of std::optional<T>, and Y is of T or similar.
2025-06-08 22:37:59 -07:00
stma247
72b2d4d758
[llvm-cov] Fix branch counts of template functions (second attempt) (#135074)
This PR is a second attempt for issue #111743 to finish reverted PR
#113925.

Added option "--unify-instantiations" to llvm-cov export to combine branch execution counts of C++ template instantiations.  Fix non-deterministic behavior.
2025-04-24 11:35:09 -05:00
Kazu Hirata
59288761c9
[llvm] Use llvm::binary_search (NFC) (#136228) 2025-04-17 21:46:24 -07:00
Kazu Hirata
8db434a481
[bugpoint] Avoid repeated hash lookups (NFC) (#133616) 2025-03-29 22:40:05 -07:00
NAKAMURA Takumi
6a9d0e53ae [llvm-cov] Prevent assertion failure in sumMCDCPairs
Since #112694, MCDCRecord::isCondFolded() has returned true for
"partially folded" conditions. Besides,
isConditionIndependencePairCovered() returns true if the unfolded
condition is satisfied. This might break consistency
(CoveredPairs <= NumPairs).
2025-01-28 14:56:58 +09:00
NAKAMURA Takumi
a21f13bde2
llvm-cov: Refactor CoverageSummaryInfo. NFC. (#121189)
- Let subfunctions return `CoverageInfo` objects w/o accumulating
  reference values.
- Introduce `CoverageDataSummary` for handling `CoverageData`-oriented
  metrics.
2024-12-28 17:49:10 +09:00
NAKAMURA Takumi
aa2fdc69d3
[Coverage] Move SingleByteCoverage out of CountedRegion (#110966)
`SingleByteCoverage` is not per-region attribute at least.
Move it into `CoverageData` since it comes from `profdata`.

Depends on: #120841
2024-12-27 20:42:26 +09:00
NAKAMURA Takumi
223521b13e
llvm-cov: Introduce --binary-counters (#120841)
In `llvm-cov show`, this option rounds counters (line, branch) to
`[1,0]` at rendering. This will be useful when the number of counts
doesn't interest but **Covered/uncoverd** does.
2024-12-27 19:48:30 +09:00
NAKAMURA Takumi
3d9f9684a5 llvm-cov: Split out sumRegions() from FunctionCoverageSummary::get(). NFC. 2024-12-27 14:37:01 +09:00
NAKAMURA Takumi
90726652c9 Reformat 2024-12-22 15:02:04 +09:00
NAKAMURA Takumi
4e3c0bb7f7
llvm-cov: Introduce -show-created-time to suppress timestamps (#120417)
This shouldn't affect anything since `-show-created-time=true` by
default.

Timestamps sometimes prevent reproducible build.
2024-12-20 11:31:01 +09:00
NAKAMURA Takumi
a9df1f6cb0 llvm-cov: Refactor SourceCoverageView::renderBranchView().
NFC except for calculating `Total`. I've replaced
`(uint64_t)+(uint64_t)` with `(double)+(double)`.

This is still inexact with large numbers `(1LL << 53)` but will be expected to prevent possible overflow.
2024-12-18 20:00:03 +09:00
NAKAMURA Takumi
7384d8bc18 SourceCoverageViewHTML.cpp: Reformat JS 2024-12-18 20:00:02 +09:00
Alan Phipps
92f5314706
Revert "[llvm-cov] Fix branch counts of template functions (#111743)" (#118398)
Reverts llvm/llvm-project#113925

Reverting to address buildbot failures.
2024-12-02 15:48:22 -06:00
stma247
0fe1f8524e
[llvm-cov] Fix branch counts of template functions (#111743) (#113925)
Added option "--unify-instantiations" to llvm-cov export to combine
branch execution counts of C++ template instantiations.

on-behalf-of: @e-solutions-GmbH <info@esolutions.de>
2024-12-02 14:24:15 -06:00
Kazu Hirata
4048c64306
[llvm] Remove redundant control flow statements (NFC) (#115831)
Identified with readability-redundant-control-flow.
2024-11-12 10:09:42 -08:00
NAKAMURA Takumi
4a011ac84f
[Coverage] Introduce "partial fold" on BranchRegion (#112694)
Currently both True/False counts were folded. It lost the information,
"It is True or False before folding." It prevented recalling branch
counts in merging template instantiations.

In `llvm-cov`, a folded branch is shown as:

- `[True: n, Folded]`
- `[Folded, False n]`

In the case If `n` is zero, a branch is reported as "uncovered". This is
distinguished from "folded" branch. When folded branches are merged,
`Folded` may be dissolved.

In the coverage map, either `Counter` is `Zero`. Currently both were
`Zero`.

Since "partial fold" has been introduced, either case in `switch` is
omitted as `Folded`.

Each `case:` in `switch` is reported as `[True: n, Folded]`, since
`False` count doesn't show meaningful value.

When `switch` doesn't have `default:`, `switch (Cond)` is reported as
`[Folded, False: n]`, since `True` count was just the sum of `case`(s).
`switch` with `default` can be considered as "the statement that doesn't
have any `False`(s)".
2024-10-20 12:30:35 +09:00
Kazu Hirata
74d9f7ce80
[llvm] Use std::optional::value_or (NFC) (#109890) 2024-09-24 21:49:06 -07:00
Nikita Popov
eb7ebd51ec
[llvm-cov] Remove View member from MCDCView and BranchView (#97734)
These were never actually used, and the way they were constructed
doesn't really make sense.

Fixes https://github.com/llvm/llvm-project/issues/93798.
2024-07-05 09:20:25 +02:00
Wentao Zhang
61e62ce2eb
[llvm-cov] let text mode divider honor --show-branch-summary, --show-region-summary etc (#96016) 2024-06-19 15:41:55 -05:00
Hana Dusíková
06aa078d68
[llvm-cov] Coverage report HTML UI to jump between uncovered parts of code (#95662)
I replaced "jump to first uncovered line" with UI buttons and keyboard
shortcut to jump between uncovered parts of code: lines (key L), branchs
(key B), regions (key R).

User can also jump in reverse direction with shift+key.
2024-06-17 21:30:50 +02:00
Jay Foad
d4a0154902
[llvm-project] Fix typo "seperate" (#95373) 2024-06-13 20:20:27 +01:00
EdJoPaTo
163cb1fc2f
[llvm-cov] Add HTML dark theme support (#93080)
Personally I use
[cargo-llvm-cov](https://github.com/taiki-e/cargo-llvm-cov) which
creates helpful HTML coverage reports, but they don't support a dynamic
dark themes.

I updated the styling to support both dark and bright color themes based
on the browser preference. The bright theme should look similar to the
current theme.

I also improved some color contrasts (Firefox accessibility tool
reported them) and ensured that line-number links keep their
text-decoration.

Things that both have `.tooltip` and `.red` look kinda odd as the
coloring is now based on tinting with transparency. Given that the
tooltip should always show 0 in such cases (otherwise it wouldn't be
red) the tooltip could be removed there on the HTML generation, but that
seemed out of scope for my style only change.
2024-06-05 14:35:43 +02:00
Mehdi Amini
716042a63f
Rename llvm::ThreadPool -> llvm::DefaultThreadPool (NFC) (#83702)
The base class llvm::ThreadPoolInterface will be renamed
llvm::ThreadPool in a subsequent commit.

This is a breaking change: clients who use to create a ThreadPool must
now create a DefaultThreadPool instead.
2024-03-05 18:00:46 -08:00
Mehdi Amini
6594f428de
Split the llvm::ThreadPool into an abstract base class and an implementation (#82094)
This decouples the public API used to enqueue tasks and wait for
completion from the actual implementation, and opens up the possibility
for clients to set their own thread pool implementation for the pool.

https://discourse.llvm.org/t/construct-threadpool-from-vector-of-existing-threads/76883
2024-03-02 19:10:50 -08:00
Wentao Zhang
0bf4f82f66
[llvm-cov][CoverageView] minor fix/improvement to HTML and text coverage output (#80952)
1. add the missing condition for MC/DC in hasSubViews()
2. add style for selected line
3. remove name="Ln" attribute in the link within MC/DC views
4. remove color for \n
2024-02-16 23:24:31 -06:00
Fangrui Song
927919ac34 [llvm-cov] Simplify branch/MCDC subviews. NFC
Remove unneeded empty check and reundant copies. NFC
2024-01-27 16:00:37 -08:00
Hana Dusíková
865e4a1f33
[coverage] skipping code coverage for 'if constexpr' and 'if consteval' (#78033)
`if constexpr` and `if consteval` conditional statements code coverage
should behave more like a preprocesor `#if`-s than normal
ConditionalStmt. This PR should fix that.

---------

Co-authored-by: cor3ntin <corentinjabot@gmail.com>
2024-01-22 12:50:20 +01:00
Kazu Hirata
c03c4e2b14 [tools] Use SmallString::operator std::string (NFC) 2024-01-19 00:19:31 -08:00
Hana Dusíková
18e1179208 [llvm-cov] format cells in report with 0/0 branches/functions/lines differenly (gray instead red) and make the table a bit nicer (#75780) 2023-12-19 19:15:39 +09:00
Alan Phipps
8ecbb0404d Reland "[Coverage][llvm-cov] Enable MC/DC Support in LLVM Source-based Code Coverage (2/3)"
Part 2 of 3. This includes the Visualization and Evaluation components.

Differential Revision: https://reviews.llvm.org/D138847
2023-12-13 15:10:05 -06:00
Kazu Hirata
cc4ecfd68b
[ADT] Rename SmallString::{starts,ends}with to {starts,ends}_with (#74916)
This patch renames {starts,ends}with to {starts,ends}_with for
consistency with std::{string,string_view}::{starts,ends}_with in
C++20.  Since there are only a handful of occurrences, this patch
skips the deprecation phase and simply renames them.
2023-12-09 14:28:45 -08:00
Kazu Hirata
fcb160eabc [llvm] Stop including llvm/ADT/DenseMap.h (NFC)
Identified with clangd.
2023-11-11 22:46:28 -08:00
Alan Phipps
ab3cd075b3 Revert "[Coverage][llvm-cov] Enable MC/DC Support in LLVM Source-based Code Coverage (2/3)"
This reverts commit 618a22144db5e45da8c95dc22064103e1b5e5b71.

Buildbots failing on windows and one other issue.
2023-09-20 16:32:34 -05:00
Alan Phipps
618a22144d [Coverage][llvm-cov] Enable MC/DC Support in LLVM Source-based Code Coverage (2/3)
Part 2 of 3. This includes the Visualization and Evaluation components.

Differential Revision: https://reviews.llvm.org/D138847
2023-09-20 15:30:47 -05:00
MaggieYingYi
cd8fe1dbcb
[llvm-cov] - Output better error message when the error kind is coveragemap_error::malforme. (#65264)
The current llvm-cov error message for kind `coveragemap_error::malforme`, just gives the issue kind without any reason for what caused the issue. This patch is aimed at improving the llvm-cov error message to help identify what caused the issue.

Reviewed By: MaskRay
Close: https://github.com/llvm/llvm-project/pull/65264
2023-09-06 15:02:31 +01:00
Yuhao Gu
bea39c5443 [llvm-cov] Support directory layout in coverage reports
This is a GSoC 2023 project ([discourse link](https://discourse.llvm.org/t/coverage-support-a-hierarchical-directory-structure-in-generated-coverage-html-reports/68239)).

llvm-cov currently generates a single top-level index HTML file, which causes rendering scalability issues in large projects. This patch adds support for hierarchical directory structure into the HTML reports to solve scalability issues by introducing the following changes:

- Added a new command line option `--show-directory-coverage` for `llvm-cov show`. It works both for `--format=html` and `--format=text`.
- Two new classes: `CoveragePrinterHTMLDirectory` and `CoveragePrinterTextDirectory` was added to support the new option.
- A tool class `DirectoryCoverageReport` was added to support the two classes above.
- Updated the document.
- Added a new regression test for `--show-directory-coverage`.

Reviewed By: phosek, gulfem

Differential Revision: https://reviews.llvm.org/D151283
2023-08-24 13:46:12 +08:00
Tomas Camin
5042e1e56d
[llvm-cov] Allow multiple remaps in --path-equivalence
Previously the --path-equivalence parameter would allow to specify a single remap pair (coverage data path - local source file path). This patch changes this allowing to pass as many remaps as needed.

Reviewed By: keith

Differential Revision: https://reviews.llvm.org/D154223
2023-08-23 15:27:56 -07:00
Yuhao Gu
57cb2f6ffe Reland "[llvm-cov] Support multi-source object files for convert-for-testing"
`llvm-cov convert-for-testing` only functions properly when the input binary contains a single source file. When the binary has multiple source files, a `Malformed coverage data` error will occur when the generated .covmapping is read back. This is because the testing format lacks support for indicating the size of its file records, and current implementation just assumes there's only one record in it. This patch fixes this problem by introducing a new testing format version.

Changes to the code:

- Add a new format version. The version number is stored in the the last 8 bytes of the orignial magic number field to be backward-compatible.
- Output a LEB128 number before the file records section to indicate its size in the new version.
- Change the format parsing code correspondingly.
- Update the document to formalize the testing format.
- Additionally, fix the bug when converting COFF binaries.

Reviewed By: phosek, gulfem

Differential Revision: https://reviews.llvm.org/D156611
2023-08-18 16:43:45 +00:00
Flightor
efa8374f6b [llvm-cov] Use uint64_t to avoid overflow in addition
Reviewed By: alanphipps
Differential Revision: https://reviews.llvm.org/D157608
2023-08-18 16:51:29 +08:00
Gulfem Savrun Yeniceri
5222733b4c Revert "[llvm-cov] Fix a bug about using convert-for-testing on multi-source object files"
This reverts commit f8ad86c23405168a8cd189590184fdcc296627e0 because
it broke some downsteam tests reported in https://reviews.llvm.org/D156611.
2023-08-15 20:28:30 +00:00
Yuhao Gu
f8ad86c234 [llvm-cov] Fix a bug about using convert-for-testing on multi-source object files
`llvm-cov convert-for-testing` is used to build the .covmapping files used in its regression tests. However the current implementation only works when there's only one source file in the mapping information data. If there are more than 1 source files, `llvm-cov convert-for-testing` can still produce a .covmapping file, but when read it back, `llvm-cov` will report:

```
error: Failed to load coverage: 'main.covmapping': Malformed coverage data
```

This is because the output .covmapping file doesn't have any mark to indicate the boundary between file records and function records, and current implementation jsut assume there's only one file record in the .covmapping file.

Changes to the code:

- Make `llvm-cov convert-for-testing` output a LEB128 number before file records to indicate its size.
- Change the testing format parsing code correspondingly.
- Update existing .covmapping files.

Reviewed By: gulfem

Differential Revision: https://reviews.llvm.org/D156611
2023-08-15 02:51:28 +00:00
Elliot Goodrich
b0abd4893f [llvm] Add missing StringExtras.h includes
In preparation for removing the `#include "llvm/ADT/StringExtras.h"`
from the header to source file of `llvm/Support/Error.h`, first add in
all the missing includes that were previously included transitively
through this header.
2023-06-25 15:42:22 +01:00