Skip to content

Fix T2C crash from unterminated LLVM basic blocks#721

Merged
jserv merged 1 commit intomasterfrom
fix-llvm
Mar 1, 2026
Merged

Fix T2C crash from unterminated LLVM basic blocks#721
jserv merged 1 commit intomasterfrom
fix-llvm

Conversation

@jserv
Copy link
Copy Markdown
Contributor

@jserv jserv commented Mar 1, 2026

When t2c_trace_ebb() compiles a block whose last instruction is a non-branching, non-terminal instruction (e.g., addi, lw, sw) with no branch_taken/branch_untaken pointers, no LLVM terminator was emitted. This produced malformed IR that crashed LLVMRunPasses during the LowerExpectIntrinsicPass.

This occurs when a block ends at a page boundary or instruction limit before block chaining is established, or when a linked block has been evicted from the cache.

This adds a safety check at the end of t2c_trace_ebb() using LLVMGetBasicBlockTerminator() to detect unterminated blocks. When found, store block->pc_end to rv->PC, flush the cycle counter, and emit ret void to return control to the interpreter.

Close #718


Summary by cubic

Fixes a crash during LLVMRunPasses (LowerExpectIntrinsicPass) by ensuring every compiled basic block is properly terminated. If a block ends without a branch or a resolvable target, we now return to the interpreter safely.

  • Bug Fixes
    • Detect unterminated LLVM basic blocks with LLVMGetBasicBlockTerminator.
    • When missing: write block->pc_end to rv->PC, flush the cycle counter, and emit ret void.
    • Prevents malformed IR when a block ends at a page boundary, hits the instruction limit, or its linked block was evicted.

Written for commit 9b56311. Summary will update on new commits.

When t2c_trace_ebb() compiles a block whose last instruction is a
non-branching, non-terminal instruction (e.g., addi, lw, sw) with no
branch_taken/branch_untaken pointers, no LLVM terminator was emitted.
This produced malformed IR that crashed LLVMRunPasses during the
LowerExpectIntrinsicPass.

This occurs when a block ends at a page boundary or instruction limit
before block chaining is established, or when a linked block has been
evicted from the cache.

This adds a safety check at the end of t2c_trace_ebb() using
LLVMGetBasicBlockTerminator() to detect unterminated blocks. When found,
store block->pc_end to rv->PC, flush the cycle counter, and emit
ret void to return control to the interpreter.

Close #718
cubic-dev-ai[bot]

This comment was marked as resolved.

@jserv jserv merged commit 48db4c1 into master Mar 1, 2026
33 checks passed
@jserv jserv deleted the fix-llvm branch March 1, 2026 12:30
@jserv jserv added this to the release-2026.2 milestone Mar 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LLVMRunPasses crashes due to unterminated basic block

1 participant