boot2

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

commit 4397e4001298c337bfdae8d1422a8570f904afaf
parent 274d7069637174dad3a714ee34d3da529e6a1399
Author: Ryan Sepassi <rsepassi@gmail.com>
Date:   Sun, 26 Apr 2026 22:51:34 -0700

cc tests: pointer comparisons use unsigned ltu (§K.6)

cg-binop's lt/le/gt/ge dispatch already picks the unsigned variant
when either operand is ptr/arr (%ctype-unsigned? is #t for both).
Fixtures lock that in: cc-cg drives cg-binop directly, cc-parse
exercises &a[1] > &a[0] -> exit 1.

The emitted P1pp uses %ifelse_ltu (unsigned), confirming the
dispatch path.

Diffstat:
Atests/cc-cg/68-ptr-cmp.expected-exit | 1+
Atests/cc-cg/68-ptr-cmp.scm | 31+++++++++++++++++++++++++++++++
Atests/cc-parse/75-ptr-cmp.c | 7+++++++
Atests/cc-parse/75-ptr-cmp.expected-exit | 1+
4 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/tests/cc-cg/68-ptr-cmp.expected-exit b/tests/cc-cg/68-ptr-cmp.expected-exit @@ -0,0 +1 @@ +1 diff --git a/tests/cc-cg/68-ptr-cmp.scm b/tests/cc-cg/68-ptr-cmp.scm @@ -0,0 +1,31 @@ +;; tests/cc-cg/68-ptr-cmp.scm — pointer comparison via unsigned ltu (§K.6). +;; Models: +;; int main(void) { +;; int x = 0; int y = 0; +;; int *a = &x; int *b = &y; +;; /* The two slots' relative order in the frame is fixed by +;; * cg-alloc-slot, but we only care that the comparison is +;; * unsigned. */ +;; return (a < b) || (b < a); /* one of them must be true */ +;; } +;; Returns 1 — locks in that cg-binop dispatches to the unsigned +;; variant when either operand is ptr/arr. + +(let* ((cg (cg-init)) + (params (cg-fn-begin cg "main" '() %t-i32)) + (x-sl (cg-alloc-slot cg 4 4)) + (y-sl (cg-alloc-slot cg 4 4)) + (x-sym (%sym "x" 'var 'auto %t-i32 x-sl)) + (y-sym (%sym "y" 'var 'auto %t-i32 y-sl))) + ;; (a < b) || (b < a) — without short-circuit. Take addresses + ;; explicitly and feed cg-binop 'lt twice. + (cg-push-sym cg x-sym) (cg-take-addr cg) + (cg-push-sym cg y-sym) (cg-take-addr cg) + (cg-binop cg 'lt) + (cg-push-sym cg y-sym) (cg-take-addr cg) + (cg-push-sym cg x-sym) (cg-take-addr cg) + (cg-binop cg 'lt) + (cg-binop cg 'or) + (cg-return cg) + (cg-fn-end cg) + (write-bv-fd 1 (cg-finish cg))) diff --git a/tests/cc-parse/75-ptr-cmp.c b/tests/cc-parse/75-ptr-cmp.c @@ -0,0 +1,7 @@ +/* §K.6 — pointer comparison is unsigned. + * &a[1] is one int past &a[0], so the comparison is well-defined and + * the result of the > comparison is exactly 1. */ +int main(void) { + int a[2]; + return &a[1] > &a[0]; +} diff --git a/tests/cc-parse/75-ptr-cmp.expected-exit b/tests/cc-parse/75-ptr-cmp.expected-exit @@ -0,0 +1 @@ +1