nx_self_host_load_codegen_repro.nx source
↩ module page · 52 lines · 1946 B
1// nx_self_host_load_codegen_repro.nx -- MINIMAL REPRO for the
2// self-host codegen bug surfaced by the bootstrap-stability audit
3// + fixed-point audit on 2026-05-21.
4//
5// Bug class: the native x86_64 NishiLang binary (built via the
6// bootstrap loop from the qemu-RV64 substrate) emits INCORRECT
7// asm for two specific patterns:
8//
9// A. return <local-variable>:
10// Expected: movq <slot>(%rbp), %rax ; ret
11// Got: movabsq $0, %rax ; ret <-- WRONG: returns 0
12//
13// B. call <named-function>:
14// Expected: call sys_mmap (or other name)
15// Got: call <garbage-bytes-as-string> <-- WRONG: name corrupted
16//
17// Both fail patterns involve reading from memory that was written
18// earlier (the stack slot for the local; the name-string buffer
19// for the function name). Common factor: memory-load codegen
20// emitted by the substrate-compiled native binary is broken
21// somehow. The qemu-RV64 substrate emits these patterns CORRECTLY
22// for user code, so the bug is baked into the native binary
23// itself by the RV64-qemu compiler when it emits nx_compile_x86.nx
24// + nx_opt.nx + nx_x86_64_ctx.nx asm.
25//
26// This source is itself a TEST PROGRAM (returns expected 18 = 7+11)
27// AND a self-host-bootstrap regression KAT. When the substrate
28// codegen bug is fixed:
29//
30// 1. The bash test runs this binary natively, expects exit 18.
31// 2. The bootstrap-stability audit (bench/nx_bootstrap_stability_audit.sh)
32// passes for nx_u8_load_test.nx etc.
33// 3. The fixed-point audit (bench/nx_self_host_fixed_point_audit.sh)
34// returns PASS (stage_2.s == stage_3.s).
35//
36// Until that bug is fixed, this KAT is the SMALLEST repro:
37// 7-line function with two locals + return-sum.
38//
39// expect_exit: 18
40// license_tier: ORIGINAL
41
42import "nx_syscalls.nx"
43
44func foo() -> i64 {
45 let a: i64 = 7
46 let b: i64 = 11
47 return a + b
48}
49
50func main() -> i64 {
51 return foo()
52}