080-uneg-canonical.scm (862B)
1 ;; tests/cc-cg/80-uneg-canonical.scm — unary minus on unsigned should 2 ;; leave the canonical 64-bit slot in the to-type's natural form. 3 ;; 4 ;; Models: 5 ;; unsigned int a = 1; 6 ;; return ((unsigned)-a) == 4294967295u; /* (u32)-1u == UINT_MAX */ 7 ;; 8 ;; Bug: cg-unop neg computes 0 - canonical(1) = 0xFFFFFFFFFFFFFFFF and 9 ;; spills as u32. Without re-canonicalizing the spill (zext32), a 10 ;; subsequent compare against the literal 4294967295 (which %li loads 11 ;; as 0x00000000FFFFFFFF) sees mismatched upper bits → equality 0. 12 ;; Correct cg masks/zext on spill of an unsigned-typed result. 13 ;; Exit code: 1 if equal, 0 otherwise. 14 15 (let ((cg (cg-init))) 16 (cg-fn-begin cg "main" '() %t-i32) 17 (cg-push-imm cg %t-u32 1) 18 (cg-unop cg 'neg) 19 (cg-push-imm cg %t-u32 4294967295) 20 (cg-binop cg 'eq) 21 (cg-return cg) 22 (cg-fn-end cg) 23 (write-bv-fd 1 (cg-finish cg)))