{"record":{"id":"6d8f43fb5b72bbe5","repo":"rust-lang/rust","slug":"unexpected-base-kind-for-gap-region-kind","errorCode":null,"errorMessage":"unexpected base kind for gap region: {kind:?}","messagePattern":"unexpected base kind for gap region: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/tools/coverage-dump/src/covfun.rs","lineNumber":189,"sourceCode":"impl<'a> Parser<'a> {\n    fn read_simple_term(&mut self) -> anyhow::Result<CovTerm> {\n        let raw_term = self.read_uleb128_u32()?;\n        CovTerm::decode(raw_term).context(\"decoding term\")\n    }\n\n    fn read_mapping_kind_and_region(&mut self) -> anyhow::Result<(MappingKind, MappingRegion)> {\n        let mut kind = self.read_raw_mapping_kind()?;\n        let mut region = self.read_raw_mapping_region()?;\n\n        const HIGH_BIT: u32 = 1u32 << 31;\n        if region.end_column & HIGH_BIT != 0 {\n            region.end_column &= !HIGH_BIT;\n            kind = match kind {\n                MappingKind::Code(term) => MappingKind::Gap(term),\n                // LLVM's coverage mapping reader will actually handle this\n                // case without complaint, but the result is almost certainly\n                // a meaningless implementation artifact.\n                _ => return Err(anyhow!(\"unexpected base kind for gap region: {kind:?}\")),\n            }\n        }\n\n        Ok((kind, region))\n    }\n\n    fn read_raw_mapping_kind(&mut self) -> anyhow::Result<MappingKind> {\n        let raw_mapping_kind = self.read_uleb128_u32()?;\n        if let Some(term) = CovTerm::decode(raw_mapping_kind) {\n            return Ok(MappingKind::Code(term));\n        }\n\n        assert_eq!(raw_mapping_kind & 0b11, 0);\n        assert_ne!(raw_mapping_kind, 0);\n\n        let (high, is_expansion) = (raw_mapping_kind >> 3, raw_mapping_kind & 0b100 != 0);\n        if is_expansion {\n            Ok(MappingKind::Expansion(high))","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/src/tools/coverage-dump/src/covfun.rs#L171-L207","documentation":"Thrown by read_mapping_kind_and_region in coverage-dump's covfun parser when a mapping region has the gap high bit set (bit 31 of end_column) but the decoded kind is not MappingKind::Code. Per LLVM's coverage format, the gap bit converts a Code mapping into a Gap mapping; any other base kind (Expansion, Skip, Branch, MCDC*) with the gap bit is treated as a meaningless artifact and rejected rather than silently mishandled.","triggerScenarios":"Parsing a coverage mapping record produced by an LLVM version that emits gap regions for non-Code mapping kinds, or by a malformed/corrupted coverage payload where the gap bit coincidentally collides with an already-specialized kind. Most commonly seen when coverage-dump is run against output from a newer/changed LLVM instrumentation.","commonSituations":"LLVM coverage instrumentation changed and now sets the gap bit on a branch/expansion region; a hand-crafted or truncated covfun payload; version skew between the rustc that produced the coverage and the coverage-dump parsing it.","solutions":["Confirm the coverage artifact was produced by an LLVM version compatible with this coverage-dump parser.","Re-generate the coverage data with the toolchain matching coverage-dump.","If this is a new legitimate LLVM behavior, extend read_mapping_kind_and_region to handle the new kind combination rather than treating it as an error.","Report the raw kind value (printed in the error) to identify which MappingKind variant collided."],"exampleFix":"null","handlingStrategy":"try-catch","validationCode":"// Before bulk parsing, this is an internal-format error; the best prevention is\n// ensuring producer/dumper versions match. No caller-side validation is meaningful\n// beyond checking the LLVM IR source toolchain version.","typeGuard":null,"tryCatchPattern":"if let Err(e) = dump_covfun_mappings(llvm_ir, &filename_tables, &function_names) {\n    if e.to_string().contains(\"unexpected base kind for gap region\") {\n        eprintln!(\"{e:#}. Likely version skew between coverage producer and coverage-dump.\");\n    }\n    return Err(e);\n}","preventionTips":["Keep coverage-dump in lockstep with the LLVM that produced the coverage data.","Re-generate coverage artifacts if you see unexpected kind combinations.","When LLVM changes its mapping format, update read_mapping_kind_and_region."],"tags":["coverage-dump","llvm","coverage","parsing"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}