Skip to content

[Coverage] Line coverage contains invalid counts #171822

@sebastianzander

Description

@sebastianzander

In our codebase, llvm-cov export --format=lcov produces some weird, unrealistic high line hit counts, especially considering the line counts surrounding them within the same region. Find an example of a slightly obfuscated function together with the LCOV output below:

  int DisplayIdManager::findNewDisplayID( const Framework &workingFw, const Framework &orderingFw,
    const QString &businessKey, const QString &orderKey )
  { // line 330
    Q_ASSERT( !parentBusinessKey.isEmpty() && !orderKey.isEmpty() );

    // try to find in cache at first
    int displayID = displayIdCache.maxDisplayId( orderKey, businessKey );
    if ( displayID > 0 )
    {
      ++displayID;
      displayIdCache.setMaxDisplayId( orderKey, businessKey, displayID );
      return displayID;
    }

    int workingVersionID = getVersionIdByType( workingFw, versionTypes_c::WORKING ); // line 342
    int orderingVersionID = getVersionIdByType( orderingFw, versionTypes_c::ORDERING );

    // unrelated comment
    const auto &foo = fetch< SomeDataList >( workingFw );
    ...
SF:/opt/.../display_id_mgr.cpp
...
DA:330,77568
DA:331,77568
DA:334,77568
DA:335,77568
DA:336,78033
DA:337,78033
DA:338,78033
DA:339,78033
DA:340,78033
DA:342,18446744073709551151
DA:343,18446744073709551151
DA:346,18446744073709551151
DA:348,18446744073709551151
DA:349,2
DA:350,2
...

It is weird, because these lines are unconditionally executed and the count of lines before and after seems normal.

In total, it is 38 from 1.5M analyzed lines that have this issue.

The issue appears when trying to upload the LCOV file to a service like e.g. CodeScene. Their CLI tools expect a 32-bit integer. I couldn't find a strict specification of the LCOV format. So perhaps this is not an issue here but with the CodeScene CLI.

LLVM version: 16.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions