082-uadd-wrap-canonical.scm (648B)
1 ;; tests/cc-cg/82-uadd-wrap-canonical.scm — unsigned add must wrap 2 ;; correctly into the canonical 64-bit slot form. 3 ;; 4 ;; Models: 5 ;; unsigned int a = 4294967295u; 6 ;; return (a + 1u) == 0u; 7 ;; 8 ;; Bug: cg-binop add computes 0xFFFFFFFF + 1 = 0x100000000 in 64-bit. 9 ;; Spilled as u32 without zero-extending the low 32 bits, the result 10 ;; compares unequal to 0u (which loads as 0x0). 11 12 (let ((cg (cg-init))) 13 (cg-fn-begin cg "main" '() %t-i32) 14 (cg-push-imm cg %t-u32 4294967295) 15 (cg-push-imm cg %t-u32 1) 16 (cg-binop cg 'add) 17 (cg-push-imm cg %t-u32 0) 18 (cg-binop cg 'eq) 19 (cg-return cg) 20 (cg-fn-end cg) 21 (write-bv-fd 1 (cg-finish cg)))