LLVM2LCOV(1)

πŸ“¦
version 2.6 Β· 2 versions
, in arch rolling

πŸ’… LLVM2LCOV(1) β€” the LCOV tools girlies ✨

okay so first things first, this is a page from the LCOV Tools manual group, and it lives in Manual section 1. The tool itself is llvm2lcov, and if you only remember one thing about it, remember this: it translates LLVM coverage data from llvm-cov profdata into LCOV format. that's the whole vibe. πŸŽ€


🌸 NAME 🌸

llvm2lcov β€” literally just the docs for llvm2lcov, bestie. and like, what does it do? it translates LLVM coverage data from llvm-cov profdata to LCOV format. iconic behavior honestly. πŸ‘‘


✨ SYNOPSIS ✨

llvm2lcov [--output filename] [--testname name] [options] json_file [json_file ...]

πŸ¦‹ DESCRIPTION πŸ¦‹

so llvm2lcov goes wandering through your C/C++ coverage data in JSON format (the kind that comes out of llvm-cov export -format=text ...) and translates all of it into LCOV .info format. slay. that's the job. πŸ’–

okay but real talk, heads up: LLVM has two coverage data collection paths, and they are not the same thing, no cap:

  • the one this page is about β€” the profile data path
  • a gcov path β€” basically the same kind of thing gcc supports

if you wanna know more about the gcov support in LLVM, go check the LLVM documentation. iykyk. πŸ“š


🌈 MC/DC COVERAGE 🌈

want MC/DC data? bet. here's the recipe:

  • Use LLVM 18 or newer (LLVM 21+ recommended for cleaner MC/DC data) β€” newer is giving cleaner vibes, trust.
  • Enable MC/DC instrumentation in your compile/link steps with -fcoverage-mcdc
  • Pass the --mcdc-coverage flag to llvm2lcov
⚠️ also important: LLVM does not support MC/DC metrics when using the gcov data collection path. so don't try it. it's not happening. πŸ’€

🧚 OPTIONS 🧚

on top of all the common options the other tools in the LCOV suite support (think --comment, --version-script, --ignore-error, --substitute, --exclude, etc. β€” you know the ones), this tool also serves these:

  • --output filename, -o filename β€” your LCOV data gets written to the file you name here. skip this option and it'll just drop it in llvm2lcov.info in whatever your current directory is. default behavior, cute. πŸ“
  • --testname name, -t name β€” associates your coverage info with the testcase name you give it. and honestly? it's not necessary to provide a name. no pressure bestie, optional. πŸ’œ
  • --branch-coverage β€” include branch coverage data in the output. go off. 🌿
  • --mcdc-coverage β€” include MC/DC data in the output. requires LLVM 18 or higher, with MC/DC instrumentation enabled during compilation. don't forget that part. πŸ”₯

for the deets on the other options and configuration settings, go look at lcov(1) and lcovrc(5). they got you. 🫢


⭐ EXAMPLES ⭐

basic workflow β€” the full glow-up pipeline:

# Compile with coverage instrumentation (including MC/DC)
$ clang++ -o myExe -fprofile-inst-generate -fcoverage-mapping \
    -fcoverage-mcdc myCode.cpp

# Run your testcases
$ ./myExe ...

# Convert profile data
$ llvm-profdata merge -o myExe.profdata --sparse *.profraw

# Export coverage data in JSON format
$ llvm-cov export -format=text -instr-profile=myExe.profdata \
    ./myExe > myExe.json

# Convert to LCOV format
$ llvm2lcov --output myExe.info --test-name myTestcase \
    --mcdc-coverage --branch-coverage myExe.json ...

# Generate HTML coverage report
$ genhtml -o html_report myExe.info ...

(those ... are just other tool options you might be using β€” like for filtering and exclusion. not me forgetting them, they're literally placeholders πŸ’…)


and doing the same example via gcov? it looks like this:

# Compile with gcov instrumentation
$ clang++ -o myExe --coverage myCode.cpp

# Run your testcases
$ ./myExe ...

# Convert to LCOV format
#   Note that the '--gcov-tool' option appears *twice*: once to name
#   the tool and once to pass a tool option.  See the lcov man page
#   for more information.
$ lcov --capture -d . --branch-coverage -o myExe.info --gcov-tool llvm-cov --gcov-tool gcov ...

# Generate HTML coverage report
$ genhtml -o html_report myExe.info ...
πŸ‘€ yes, --gcov-tool shows up twice β€” once to name the tool and once to pass a tool option. that's not a typo, that's the assignment. the lcov man page has more if you need it.

πŸ’– AUTHOR πŸ’–

Henry Cox <<henry.cox@mediatek.com>> β€” the main character who wrote this. we stan. πŸ‘‘


πŸ”₯ SEE ALSO πŸ”₯


Copyright 2024-2026, LCOV Project. all rights reserved, respectfully. πŸ’œ


and that's the whole page bestie ✨ this was version 2.6, dated 2026-10-03, and yes it's the LLVM2LCOV(1) page β€” go forth and get those coverage numbers up, you absolute legend πŸ¦‹

πŸ“¦ where this page comes from