015-char-roundtrip.scm (1227B)
1 ;; tests/cc-cg/15-char-roundtrip.scm — width-correct byte load/store 2 ;; on adjacent unsigned-char lvals. 3 ;; 4 ;; Models: 5 ;; unsigned char a = 0xAA, b = 0xBB; 6 ;; return a == 0xAA; 7 ;; 8 ;; Two 1-byte slots are allocated back-to-back at offsets 0 and 1. 9 ;; If cg uses 8-byte %ld/%st on byte-typed lvals, the second store 10 ;; contaminates the first slot (byte 0 stays 0xAA but byte 1 becomes 11 ;; 0xBB) and the load of `a` yields 0xBBAA — which fails the equality 12 ;; test. Width-aware emission (%lb / %sb on size-1 ctype) yields 13 ;; exactly 0xAA, the comparison is true, and exit is 1. 14 15 (let ((cg (cg-init))) 16 (cg-fn-begin cg "main" '() %t-i32) 17 (let* ((off-a (cg-alloc-slot cg 1 1)) 18 (off-b (cg-alloc-slot cg 1 1)) 19 (sym-a (%sym "a" 'var 'auto %t-u8 off-a)) 20 (sym-b (%sym "b" 'var 'auto %t-u8 off-b))) 21 ;; a = 0xAA 22 (cg-push-sym cg sym-a) 23 (cg-push-imm cg %t-u8 170) 24 (cg-assign cg) (cg-pop cg) 25 ;; b = 0xBB 26 (cg-push-sym cg sym-b) 27 (cg-push-imm cg %t-u8 187) 28 (cg-assign cg) (cg-pop cg) 29 ;; return a == 0xAA 30 (cg-push-sym cg sym-a) 31 (cg-load cg) 32 (cg-push-imm cg %t-u8 170) 33 (cg-binop cg 'eq) 34 (cg-return cg)) 35 (cg-fn-end cg) 36 (write-bv-fd 1 (cg-finish cg)))