code wiki / (root) / smoke_codegen_bug.nx

smoke_codegen_bug.nx source

↩ module page · 28 lines · 631 B

1// Minimal repro for the nested-if codegen bug: 2// outer if + 2 sequential inner ifs reading from the same struct 3// pointer crashes when run under qemu. 4 5import "syscalls.nx" 6 7struct Cell { 8 a: i64, 9 b: i64, 10 c: i64, 11} 12 13func main() -> i64 { 14 let buf: *u8 = sys_mmap(64) 15 let p: *Cell = buf as *Cell 16 p.a = 5 17 p.b = 7 18 p.c = 11 19 20 var n: i64 = 0 21 while n < 3 { 22 if p.a >= 0 { 23 if p.b >= 0 { n = n + 1 } 24 if p.b < 0 { n = n + 100 } // dead branch, but presence triggers bug? 25 } 26 } 27 return __syscall(93, n & 0xFF, 0, 0, 0, 0, 0) 28}