code wiki / (root) / smoke_repro.nx

smoke_repro.nx source

↩ module page · 41 lines · 838 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 7import "syscalls.nx" 8 9struct S { 10 a: i64, 11 b: i64, 12 c: i64, 13} 14 15func work(L: *S) -> i64 { 16 let raw: *u8 = sys_mmap(64) 17 let t: *S = raw as *S 18 t.a = 0 19 t.b = 0 20 t.c = 0 21 var i: i64 = 0 22 while i < 3 { 23 let v: i64 = L.a + L.b 24 if v >= 0 { 25 t.a = t.a + v 26 i = i + 1 27 } 28 if v < 0 { break } 29 } 30 return t.a 31} 32 33func main() -> i64 { 34 let raw: *u8 = sys_mmap(64) 35 let L: *S = raw as *S 36 L.a = 1 37 L.b = 2 38 L.c = 0 39 let r: i64 = work(L) 40 return __syscall(93, r, 0, 0, 0, 0, 0) 41}