code wiki / (root) / nx_smoke_repro.nx

nx_smoke_repro.nx source

↩ module page · 47 lines · 1051 B

1// smoke_repro.nx -- minimal repro of codegen bug. 2// 3// Mirrors lex.nx's lex_ident_or_kw shape: alloc one struct, 4// init fields, alloc another struct, init fields, while loop 5// that reads struct fields. Should exit 7. 6 7// nx_safety_envelope: 8// intended_use: AUTO_APPLIED -- primitive-specific tuning queued 9// sil_target: SIL1 10// evidence: [bulk_applied_2026-05-16, see-file-comment-for-detail] 11// verdict: NOT_YET_EVALUATED 12 13import "nx_syscalls.nx" 14 15struct S { 16 a: i64, 17 b: i64, 18 c: i64, 19} 20 21func work(L: *S) -> i64 { 22 let raw: *u8 = sys_mmap(64) 23 let t: *S = raw as *S 24 t.a = 0 25 t.b = 0 26 t.c = 0 27 var i: i64 = 0 28 while i < 3 { 29 let v: i64 = L.a + L.b 30 if v >= 0 { 31 t.a = t.a + v 32 i = i + 1 33 } 34 if v < 0 { break } 35 } 36 return t.a 37} 38 39func main() -> i64 { 40 let raw: *u8 = sys_mmap(64) 41 let L: *S = raw as *S 42 L.a = 1 43 L.b = 2 44 L.c = 0 45 let r: i64 = work(L) 46 return __syscall(93, r, 0, 0, 0, 0, 0) 47}