{"id":"18a8f9f6b8613a26","repo":"rust-lang/rust","slug":"unknown-coverage-mapping-version-reported-by-llvm","errorCode":null,"errorMessage":"unknown coverage mapping version reported by `llvm-wrapper`: {raw_version}","messagePattern":"unknown coverage mapping version reported by `llvm-wrapper`: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs","lineNumber":52,"sourceCode":"    fn to_u32(self) -> u32 {\n        self as u32\n    }\n}\n\n/// Generates and exports the coverage map, which is embedded in special\n/// linker sections in the final binary.\n///\n/// Those sections are then read and understood by LLVM's `llvm-cov` tool,\n/// which is distributed in the `llvm-tools` rustup component.\npub(crate) fn finalize(cx: &mut CodegenCx<'_, '_>) {\n    let tcx = cx.tcx;\n\n    // Ensure that LLVM is using a version of the coverage mapping format that\n    // agrees with our Rust-side code. Expected versions are:\n    // - `Version7` (6) used by LLVM 18 onwards.\n    let covmap_version =\n        CovmapVersion::try_from(llvm_cov::mapping_version()).unwrap_or_else(|raw_version: u32| {\n            panic!(\"unknown coverage mapping version reported by `llvm-wrapper`: {raw_version}\")\n        });\n    assert_matches!(covmap_version, CovmapVersion::Version7);\n\n    debug!(\"Generating coverage map for CodegenUnit: `{}`\", cx.codegen_unit.name());\n\n    // FIXME(#132395): Can this be none even when coverage is enabled?\n    let Some(ref coverage_cx) = cx.coverage_cx else { return };\n\n    let mut covfun_records = coverage_cx\n        .instances_used()\n        .into_iter()\n        // Sort by symbol name, so that the global file table is built in an\n        // order that doesn't depend on the stable-hash-based order in which\n        // instances were visited during codegen.\n        .sorted_by_cached_key(|&instance| tcx.symbol_name(instance).name)\n        .filter_map(|instance| prepare_covfun_record(tcx, instance, true))\n        .collect::<Vec<_>>();\n","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs#L34-L70","documentation":"This panic fires in `coverageinfo::mapgen::finalize` (mapgen.rs:50-53) when the LLVM-wrapper reports a coverage mapping version that `CovmapVersion::try_from` does not recognize. rustc currently only understands `Version7` (encoded as `6`, used by LLVM 18+); any other value from `llvm_cov::mapping_version()` triggers `panic!(\"unknown coverage mapping version reported by llvm-wrapper: {raw_version}\")`. The guard ensures the Rust-side covmap writer and the LLVM-side reader agree on the binary format embedded in `__llvm_covmap`.","triggerScenarios":"Compiling with coverage instrumentation (`-Cinstrument-coverage`) on a rustc whose bundled LLVM-wrapper returns a mapping version other than `6`. Triggered during the codegen-unit finalize step (`finalize()` at mapgen.rs:44) when `llvm_cov::mapping_version()` yields an unexpected `u32`.","commonSituations":"A source build of rustc where `rustc_llvm`/`llvm-wrapper` were updated to a newer LLVM (e.g. LLVM 19/20/21) that bumped the covmap version before rustc was patched to support it; mixing a rustc checkout with a non-matching LLVM submodule; running a dev build mid-rebase across an LLVM upgrade.","solutions":["Update the rustc checkout to a commit whose `CovmapVersion` enum and `llvm-wrapper` both support the reported version.","Ensure the LLVM submodule matches the revision pinned by the rustc checkout (`./x.py build` after `git submodule update`).","Use a stable released toolchain for coverage work instead of a source build.","Disable `-Cinstrument-coverage` to bypass covmap generation until the version mismatch is resolved."],"exampleFix":"// before\nrustc +local-dev -Cinstrument-coverage main.rs   # LLVM bumped covmap version\n// after\nrustup update stable\nrustc +stable -Cinstrument-coverage main.rs","handlingStrategy":"validation","validationCode":"# Only LLVM coverage-mapping Version7 (==6) is accepted. The version comes from\n# llvm-wrapper, so the rustc and llvm-tools-preview components MUST come from the\n# same release. Validate component consistency before -Cinstrument-coverage.\nrustc_version=\"$(rustc -vV | awk '/^release:/ {print $2}')\"\nif rustup component list --installed 2>/dev/null | grep -q llvm-tools-preview; then\n  : # installed via rustup; consistency guaranteed by rustup\nelse\n  echo 'llvm-tools-preview not installed; coverage may use a mismatched LLVM' >&2\nfi\nrustc -V >/dev/null 2>&1 || { echo 'rustc missing'; exit 1; }\n# Reject toolchains where rustc and llvm-tools differ in date (nightly edge case).\nrustup show | grep -E 'rustc|llvm-tools' || true","typeGuard":null,"tryCatchPattern":"out=\"$(cargo build 2>&1)\"; rc=$?\nif [ $rc -ne 0 ]; then\n  case \"$out\" in\n    *\"unknown coverage mapping version reported by\"*)\n      echo \"rustc/llvm-tools coverage-format mismatch\" >&2\n      echo \"fix: rustup toolchain install nightly --component llvm-tools-preview --force-non-host\" >&2\n      echo \"     or upgrade to a stable release whose LLVM ships mapping Version7\" >&2 ;;\n    *) echo \"$out\" >&2 ;;\n  esac\n  exit $rc\nfi","preventionTips":["Install llvm-tools-preview from the same toolchain as rustc: `rustup component add llvm-tools-preview`.","Do not copy llvm-cov / libLLVM from a different LLVM release into the toolchain sysroot.","Pin the toolchain date in rust-toolchain.toml so coverage runs against a known-compatible LLVM.","If a nightly regresses the mapping version, fall back to -Zinstrument-coverage=off until the components resync.","Verify with `llvm-cov --version` that the tool you invoke matches the rustc-shipped LLVM major version."],"tags":["llvm","coverage","instrumentation","version-mismatch","panic"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}