bazelbuild / bazelbuild/bazel

C++20 module interfaces are omitted from LLVM coverage reports

Open
#31,115 1 comment 0 reactions 3 assignees Assigned to @iancha1992 View on GitHub
type: bug untriaged
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 16h
Merged PRs (30d)
72

Description

### Description of the bug:

When a C++20 module interface is supplied through `cc_library.module_interfaces`, Bazel's LLVM coverage report does not include that source file. Ordinary C++ sources in `srcs` are reported as expected.

This reproduces with Bazel 9.2.0, the default `rules_cc`, Clang, and LLVM native coverage.

### Which category does this issue belong to?

C++ Rules

### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

https://github.com/PikachuHyA/bazel_cxx20_modules_demo/tree/main/hello_module_coverage

https://github.com/PikachuHyA/bazel_cxx20_modules_demo/actions/runs/34828654074/job/103926525923 shows the different coverage dat file

```starlark
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")

cc_library(
name = "lib2",
module_interfaces = ["lib.cppm"],
features = ["cpp_modules"],
)

cc_test(
name = "test_with_module",
srcs = ["test.cc"],
copts = ["-DUSE_MODULE"],
deps = [":lib2"],
features = ["cpp_modules"],
)
```

`test.cc` imports `lib` and executes a function implemented in `lib.cppm`.

Coverage configuration:

```text
coverage --instrument_test_targets
coverage --experimental_use_llvm_covmap
coverage --experimental_generate_llvm_lcov
coverage --repo_env=BAZEL_USE_LLVM_NATIVE_COVERAGE=1
coverage --repo_env=BAZEL_LLVM_COV=llvm-cov
coverage --repo_env=BAZEL_LLVM_PROFDATA=llvm-profdata
```

Run:

```bash
bazel coverage :test_with_module --nocache_test_results
cat bazel-out/_coverage/_coverage_report.dat
```

### Which operating system are you running Bazel on?

ubuntu 24.04

### What is the output of `bazel info release`?

release 9.2.0

### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.

_No response_

### What's the output of `git remote get-url origin; git rev-parse HEAD` ?

```text

```

### If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.

_No response_

### Have you found anything relevant by searching the web?

_No response_

### Any other information, logs, or outputs that you want to share?

## Proposed direction

Add an optional `unfiltered_source_attributes` parameter to `coverage_common.instrumented_files_info`. `InstrumentedFilesCollector` should collect artifacts from these attributes without applying the source-extension filter, while still applying Bazel's instrumentation filter.

Then `rules_cc` could use:

```starlark
coverage_common.instrumented_files_info(
ctx = ctx,
source_attributes = ["srcs", "hdrs"],
unfiltered_source_attributes = ["module_interfaces"],
extensions = source_extensions,
)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.