100%

Section 03: LLVM Emission & Test Wrappers

Status: Complete Goal: JIT test wrappers catch uncaught panics via LLVM invoke/landingpad (no setjmp). InvokeIndirect terminators emit LLVM invoke through closure fat pointers. Void-returning Apply defines the dst variable (BUG-04-024).

Implementation summary: All items in this section have been implemented.


03.1 Two-layer test wrappers — COMPLETE

File(s): compiler/ori_llvm/src/codegen/function_compiler/impls.rs

Verified: compile_tests (line 31) generates two functions per test:

  • Inner body (_ori_test_<name>_body): compiled through ARC pipeline with fastcc
  • Outer wrapper (_ori_test_<name>): uses invoke to call inner body with catch-all landingpad

The test_wrappers map stores the outer wrapper name.

  • Two-layer test wrappers with invoke/landingpad catch-all
  • C calling convention for JIT compatibility
  • Outer wrapper name stored in test_wrappers map

03.2 InvokeIndirect terminator emission — COMPLETE

File(s): compiler/ori_llvm/src/codegen/arc_emitter/terminators.rs

Verified: ArcTerminator::InvokeIndirect dispatch arm exists at line 198. The emit_invoke_indirect method (line 392) extracts fn_ptr and env_ptr from the closure, builds args, and emits LLVM invoke with normal/unwind blocks. Void returns define dst as unit constant.

  • InvokeIndirect dispatch in emit_terminator
  • emit_invoke_indirect implemented with closure extraction + invoke

03.3 Void-return Apply dst (BUG-04-024) — COMPLETE

File(s): compiler/ori_llvm/src/codegen/arc_emitter/apply.rs

Verified: at line 277-282, when the call result is void (result is None), the code defines dst as EmittedValue::Immediate(const_i64(0)).

  • Void-return Apply defines dst as unit constant

03.4 Update evaluator run_test — COMPLETE

File(s): compiler/ori_llvm/src/evaluator/mod.rs

Verified: run_test (line 140) calls the wrapper function directly via unsafe { test_fn.call() } (line 163), checks did_panic() after (line 166), and includes ARC leak checking. No jit_run_protected is used.

  • Direct call to test wrapper (no jit_run_protected)
  • reset_panic_state() before call
  • did_panic() check after call
  • ARC leak check preserved

03.R Third Party Review Findings

  • None (section complete before plan creation).

03.N Completion Checklist

  • Two-layer test wrappers with invoke/landingpad catch-all
  • InvokeIndirect terminator emits LLVM invoke through closure
  • Void-return Apply defines dst variable (BUG-04-024 fixed)
  • Evaluator uses direct call + did_panic() (no jit_run_protected)

Exit Criteria: Met. JIT test runner uses LLVM landingpads for panic recovery. catch(expr:) works in JIT mode. BUG-04-024 resolved.