{"record":{"id":"d5db1cd3b9810c4d","repo":"BoundaryML/baml","slug":"missing-trap-pc-for-dead-unreachable-jump-target","errorCode":null,"errorMessage":"missing trap PC for dead-unreachable jump target","messagePattern":"missing trap PC for dead-unreachable jump target","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"baml_language/crates/baml_compiler2_emit/src/emit.rs","lineNumber":2738,"sourceCode":"                };\n                target = target.wrapping_add_signed(next_offset);\n            }\n            self.patch_jump_to(source, target);\n        }\n    }\n\n    /// Resolve a pending jump target to a concrete bytecode PC.\n    fn resolve_pending_target_pc(&self, target: PendingJumpTarget) -> usize {\n        match target {\n            PendingJumpTarget::Block(target_block) => {\n                *self.block_addresses.get(&target_block).unwrap_or_else(|| {\n                    panic!(\n                        \"missing block address for jump target {target_block:?}; target may have been skipped without redirect resolution\"\n                    )\n                })\n            }\n            PendingJumpTarget::Trap => self.trap_pc.unwrap_or_else(|| {\n                panic!(\"missing trap PC for dead-unreachable jump target\")\n            }),\n        }\n    }\n\n    /// Patch a specific jump to a specific destination.\n    #[allow(clippy::cast_possible_wrap)]\n    fn patch_jump_to(&mut self, instruction_idx: usize, destination: usize) {\n        let offset = destination as isize - instruction_idx as isize;\n        match self.bytecode.instructions[instruction_idx] {\n            Instruction::Jump(_) => {\n                self.bytecode.instructions[instruction_idx] = Instruction::Jump(offset);\n            }\n            Instruction::PopJumpIfFalse(_) => {\n                self.bytecode.instructions[instruction_idx] = Instruction::PopJumpIfFalse(offset);\n            }\n            Instruction::JumpIfFalse(_) => {\n                self.bytecode.instructions[instruction_idx] = Instruction::JumpIfFalse(offset);\n            }","sourceCodeStart":2720,"sourceCodeEnd":2756,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_compiler2_emit/src/emit.rs#L2720-L2756","documentation":"Panic in resolve_pending_target_pc for PendingJumpTarget::Trap when self.trap_pc is None. The emitter tracks the PC of an emitted trap (unreachable/dead-code) instruction so jumps to dead targets can be redirected there; if no trap was ever emitted, the dead-unreachable jump has nowhere to point. This signals an emitter invariant break: a jump was recorded as dead-target but no trap landing pad exists.","triggerScenarios":"Patching a PendingJumpTarget::Trap in a function where no trap instruction was emitted — typically when the emitter skipped emitting the trap for an unreachable region but still recorded a trap-targeted jump.","commonSituations":"Seen during compiler development when changing dead-code emission or throw handling so that a `throw` in unreachable code no longer emits a trap while jumps still reference it.","solutions":["Ensure a trap instruction is always emitted (and trap_pc recorded) whenever any jump target is marked Trap.","Redirect dead-unreachable jumps to any valid address (e.g. end of function) instead of the trap PC when no trap exists.","Capture the failing BAML input and report it as a compiler bug.","Downgrade to a version of baml-cli that does not exhibit the mis-emission."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"// compiler panic — not user-catchable; wrap the build step\nif !baml_cli_build_succeeds() {\n    pin_previous_compiler_version();\n}","preventionTips":["Emit a trap instruction whenever any jump target is marked Trap","Track trap_pc allocation alongside dead-code emission","Test throw-in-unreachable-code scenarios in CI","Keep compiler/runtime versions in lockstep"],"tags":["compiler","bytecode","panic","control-flow"],"backgroundTag":"internal-invariant-violation","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}