boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

084-bool-promotes-int.scm (950B)


      1 ;; tests/cc-cg/84-bool-promotes-int.scm — _Bool promotes to int per
      2 ;; C 6.3.1.1 (integer promotions: _Bool, char, short → int, not unsigned).
      3 ;;
      4 ;; Models:
      5 ;;   _Bool b = 1;
      6 ;;   return (b * -1) == -1;
      7 ;;
      8 ;; cg-promote currently treats bool as unsigned and promotes to u32,
      9 ;; so the subsequent arith-conv with i32 picks u32 as the common
     10 ;; type. The product 1u * (uint32_t)-1 = 0xFFFFFFFF (canonical
     11 ;; 0x00000000FFFFFFFF after spill), and the equality test against
     12 ;; (int)-1 (canonical 0xFFFFFFFFFFFFFFFF) fails. Correct cg promotes
     13 ;; bool to i32 → arith-conv keeps i32 → product is canonical i32 -1
     14 ;; → equality holds.
     15 
     16 (let ((cg (cg-init)))
     17   (cg-fn-begin cg "main" '() %t-i32)
     18   (cg-push-imm cg %t-bool 1)
     19   (cg-promote cg)
     20   (cg-push-imm cg %t-i32 -1)
     21   (cg-promote cg)
     22   (cg-arith-conv cg)
     23   (cg-binop cg 'mul)
     24   (cg-push-imm cg %t-i32 -1)
     25   (cg-binop cg 'eq)
     26   (cg-return cg)
     27   (cg-fn-end cg)
     28   (write-bv-fd 1 (cg-finish cg)))