diff options
| author | Zalathar <Zalathar@users.noreply.github.com> | 2025-05-09 20:57:17 +1000 |
|---|---|---|
| committer | Zalathar <Zalathar@users.noreply.github.com> | 2025-05-10 00:24:03 +1000 |
| commit | 078144fdfa7ae627d43cd919d660a71bef1e4658 (patch) | |
| tree | 8188e89378f1b0055d8d572cd8a037bb0f74e5e2 /tests/coverage | |
| parent | 8cd8b23b9e4b1f05373831644b005b21a13a9c69 (diff) | |
coverage: Detect unused local file IDs to avoid an LLVM assertion
This case can't actually happen yet (other than via a testing flag), because currently all of a function's spans must belong to the same file and expansion. But this will be an important edge case when adding expansion region support.
Diffstat (limited to 'tests/coverage')
| -rw-r--r-- | tests/coverage/unused-local-file.coverage | 7 | ||||
| -rw-r--r-- | tests/coverage/unused-local-file.rs | 22 |
2 files changed, 29 insertions, 0 deletions
diff --git a/tests/coverage/unused-local-file.coverage b/tests/coverage/unused-local-file.coverage new file mode 100644 index 00000000000..8f5a32f6d70 --- /dev/null +++ b/tests/coverage/unused-local-file.coverage @@ -0,0 +1,7 @@ + LL| |//@ edition: 2021 + LL| | + LL| |// Force this function to be generated in its home crate, so that it ends up + LL| |// with normal coverage metadata. + LL| |#[inline(never)] + LL| 1|pub fn external_function() {} + diff --git a/tests/coverage/unused-local-file.rs b/tests/coverage/unused-local-file.rs new file mode 100644 index 00000000000..cf43c62d703 --- /dev/null +++ b/tests/coverage/unused-local-file.rs @@ -0,0 +1,22 @@ +//! If we give LLVM a local file table for a function, but some of the entries +//! in that table have no associated mapping regions, then an assertion failure +//! will occur in LLVM. We therefore need to detect and skip any function that +//! would trigger that assertion. +//! +//! To test that this case is handled, even before adding code that could allow +//! it to happen organically (for expansion region support), we use a special +//! testing-only flag to force it to occur. + +//@ edition: 2024 +//@ compile-flags: -Zcoverage-options=inject-unused-local-file + +// The `llvm-cov` tool will complain if the test binary ends up having no +// coverage metadata at all. To prevent that, we also link to instrumented +// code in an auxiliary crate that doesn't have the special flag set. + +//@ aux-build: discard_all_helper.rs +extern crate discard_all_helper; + +fn main() { + discard_all_helper::external_function(); +} |
