From 5dd239d01e5b015dd42d8f2439e5254cfa3710b1 Mon Sep 17 00:00:00 2001 From: Hojun-Cho Date: Mon, 8 Jun 2026 23:49:16 +0900 Subject: [PATCH] wcc/cgen: #146 wwstage str ==/!= via rt_streq, not ptr-only CMPQ (the #154 ww-twin) wwstage compiled str ==/!= as a single CMPQ on the eager-eval'd ptr word (len ignored), so two distinct-pointer equal-content strings compared unequal. cstage was already correct (CALLs rt_streq, the #154 cbinop fix). The wwstage cgbin had no str-awareness -- every comparison fell to the generic CMPQ tail; the #154 fix was never mirrored. wwstage-only: a cgstreqpush helper + a str ==/!= branch at the top of cgbin (before the generic eval collapses the header), byte-matching cstage cbinop:4564-4623 -- push rhs/lhs (len,ptr), POPQ DI/SI/DX/CX, CALL rt_streq, XORQ $1 for !=. Gated on typeisstr (= cstage node_isstr, which also catches module-global str idents). cstage cgen unchanged (w6c md5 unchanged). The str== .s is byte-identical cs==ww for local, global, aliased, chained, and condition operands. Graduates 3 lib byte-id pins (test/wcc/989_lib_byteid #59.1 asciitest, #59.11 toktest, #59.12 asttest) M_DIVERGE->M_ID -- they used == on str and were pinned divergent because of this bug; now byte-identical. byte-id 990-997 8/8. test/wcc/827 table-driven. --- Makefile | 7 + selfhost/cmd/w6c/main.combined.ww | 57 +++++ selfhost/cmd/wcc/cgenexpr.ww | 57 +++++ selfhost/cmd/wwdump/main.combined.ww | 57 +++++ test/wcc/827_str_eq.c | 315 +++++++++++++++++++++++++++ test/wcc/989_lib_byteid.c | 6 +- 6 files changed, 496 insertions(+), 3 deletions(-) create mode 100644 test/wcc/827_str_eq.c diff --git a/Makefile b/Makefile index bf775ccd..68894948 100644 --- a/Makefile +++ b/Makefile @@ -255,6 +255,7 @@ TESTS = $(BIN)/test_smoke $(BIN)/test_lex $(BIN)/test_parse $(BIN)/test_check \ $(BIN)/test_inferred_float_global \ $(BIN)/test_errfirst_union_try \ $(BIN)/test_alias_tuple_coerce \ + $(BIN)/test_str_eq \ $(BIN)/test_slice_str_global_zero \ $(BIN)/test_slice_literal_global \ $(BIN)/test_global_arr_elem_field \ @@ -693,6 +694,12 @@ $(BIN)/test_alias_tuple_coerce: test/wcc/826_alias_tuple_coerce.c $(BIN)/ww \ $(LIB)/libwwrt.a | $(BIN) $(CC) $(CFLAGS) -o $@ $< +$(BIN)/test_str_eq: test/wcc/827_str_eq.c $(BIN)/ww \ + $(BIN)/w6c $(BIN)/w6a $(BIN)/w6l \ + $(BIN)/ww_ww $(BIN)/w6c_ww $(BIN)/w6a_ww $(BIN)/w6l_ww \ + $(LIB)/libwwrt.a | $(BIN) + $(CC) $(CFLAGS) -o $@ $< + $(BIN)/test_def_arr_infer_len: test/wcc/814_def_arr_infer_len.c $(BIN)/ww \ $(BIN)/w6c $(BIN)/w6a $(BIN)/w6l \ $(BIN)/ww_ww $(BIN)/w6c_ww $(BIN)/w6a_ww $(BIN)/w6l_ww \ diff --git a/selfhost/cmd/w6c/main.combined.ww b/selfhost/cmd/w6c/main.combined.ww index 170c4951..aed307d9 100644 --- a/selfhost/cmd/w6c/main.combined.ww +++ b/selfhost/cmd/w6c/main.combined.ww @@ -26856,6 +26856,43 @@ fn cgun(c: *cgen, n: *node) void = { return; }; +// cgstreqpush — push one str operand's (len, then ptr) header words for +// the rt_streq content-compare in cgbin. Mirrors cstage cgen.c:4568-4615: +// an ident loads its 2-word header (ptr+len, NOT cap) from name(SB) for a +// module-global str (#154 let_islet branch) or BP+off for a local; a +// non-ident evals via cgexpr (AX=ptr, BX=len) and pushes BX then AX. Push +// order is len then ptr so the matching POPQ pops ptr first. +fn cgstreqpush(c: *cgen, op: *node) void = { + if (op.kind == nkind.N_IDENT) { + let nm: str = op.str; + let lc: *local = localfindnode(c, nm); + if (lc == nil && isletvar(c, nm)) { + emitline("\tLEAQ\t"); + emitsymnamehint(c, nm, c.curmod); + emitline("(SB), BX\n"); + emitline("\tMOVQ\t8(BX), AX\n"); + emitline("\tPUSHQ\tAX\n"); + emitline("\tMOVQ\t(BX), AX\n"); + emitline("\tPUSHQ\tAX\n"); + return; + }; + let off: i32 = 0; + if (lc != nil) { off = lc.off; }; + emitline("\tMOVQ\t"); + emitoff((off + 8): i64); + emitline("(BP), AX\n"); + emitline("\tPUSHQ\tAX\n"); + emitline("\tMOVQ\t"); + emitoff(off: i64); + emitline("(BP), AX\n"); + emitline("\tPUSHQ\tAX\n"); + return; + }; + cgexpr(c, op); + emitline("\tPUSHQ\tBX\n"); + emitline("\tPUSHQ\tAX\n"); +}; + fn cgbin(c: *cgen, n: *node) void = { // Short-circuit `&&` / `||`. Operands are bool (0/1); the type // checker enforces it. Eval LHS into AX, branch over RHS on the @@ -26877,6 +26914,26 @@ fn cgbin(c: *cgen, n: *node) void = { return; }; + // #146 (#154 ww-twin): str ==/!= is a CONTENT compare via rt_streq, + // not a ptr compare. Must run before the generic eager-eval tail + // below collapses each str header to its ptr word (AX). Push rhs + // then lhs (len, ptr each); POPQ DI/SI/DX/CX lands a.ptr,a.len, + // b.ptr,b.len per rt/streq.s; CALL rt_streq -> AX in {0,1}; XOR 1 + // for !=. The gate reads the checker stamp (typeisstr) exactly like + // cstage node_isstr. Byte-identical to cstage cbinop (cmd/w6c/ + // cgen.c:4564-4623). cstage was fixed by #154; this is its mirror. + if ((n.op == tkind.TK_EQ || n.op == tkind.TK_NEQ) + && n.lhs != nil && n.rhs != nil + && typeisstr(n.lhs.type_: *tinfo) + && typeisstr(n.rhs.type_: *tinfo)) { + cgstreqpush(c, n.rhs); + cgstreqpush(c, n.lhs); + emitline("\tPOPQ\tDI\n\tPOPQ\tSI\n\tPOPQ\tDX\n\tPOPQ\tCX\n"); + emitline("\tCALL\trt_streq(SB)\n"); + if (n.op == tkind.TK_NEQ) { emitline("\tXORQ\t$1, AX\n"); }; + return; + }; + let unsignd: bool = nodeisunsigned(c, n.lhs); if (!unsignd) { unsignd = nodeisunsigned(c, n.rhs); }; diff --git a/selfhost/cmd/wcc/cgenexpr.ww b/selfhost/cmd/wcc/cgenexpr.ww index d946a7f5..3b84be37 100644 --- a/selfhost/cmd/wcc/cgenexpr.ww +++ b/selfhost/cmd/wcc/cgenexpr.ww @@ -5273,6 +5273,43 @@ fn cgun(c: *cgen, n: *node) void = { return; }; +// cgstreqpush — push one str operand's (len, then ptr) header words for +// the rt_streq content-compare in cgbin. Mirrors cstage cgen.c:4568-4615: +// an ident loads its 2-word header (ptr+len, NOT cap) from name(SB) for a +// module-global str (#154 let_islet branch) or BP+off for a local; a +// non-ident evals via cgexpr (AX=ptr, BX=len) and pushes BX then AX. Push +// order is len then ptr so the matching POPQ pops ptr first. +fn cgstreqpush(c: *cgen, op: *node) void = { + if (op.kind == nkind.N_IDENT) { + let nm: str = op.str; + let lc: *local = localfindnode(c, nm); + if (lc == nil && isletvar(c, nm)) { + emitline("\tLEAQ\t"); + emitsymnamehint(c, nm, c.curmod); + emitline("(SB), BX\n"); + emitline("\tMOVQ\t8(BX), AX\n"); + emitline("\tPUSHQ\tAX\n"); + emitline("\tMOVQ\t(BX), AX\n"); + emitline("\tPUSHQ\tAX\n"); + return; + }; + let off: i32 = 0; + if (lc != nil) { off = lc.off; }; + emitline("\tMOVQ\t"); + emitoff((off + 8): i64); + emitline("(BP), AX\n"); + emitline("\tPUSHQ\tAX\n"); + emitline("\tMOVQ\t"); + emitoff(off: i64); + emitline("(BP), AX\n"); + emitline("\tPUSHQ\tAX\n"); + return; + }; + cgexpr(c, op); + emitline("\tPUSHQ\tBX\n"); + emitline("\tPUSHQ\tAX\n"); +}; + fn cgbin(c: *cgen, n: *node) void = { // Short-circuit `&&` / `||`. Operands are bool (0/1); the type // checker enforces it. Eval LHS into AX, branch over RHS on the @@ -5294,6 +5331,26 @@ fn cgbin(c: *cgen, n: *node) void = { return; }; + // #146 (#154 ww-twin): str ==/!= is a CONTENT compare via rt_streq, + // not a ptr compare. Must run before the generic eager-eval tail + // below collapses each str header to its ptr word (AX). Push rhs + // then lhs (len, ptr each); POPQ DI/SI/DX/CX lands a.ptr,a.len, + // b.ptr,b.len per rt/streq.s; CALL rt_streq -> AX in {0,1}; XOR 1 + // for !=. The gate reads the checker stamp (typeisstr) exactly like + // cstage node_isstr. Byte-identical to cstage cbinop (cmd/w6c/ + // cgen.c:4564-4623). cstage was fixed by #154; this is its mirror. + if ((n.op == tkind.TK_EQ || n.op == tkind.TK_NEQ) + && n.lhs != nil && n.rhs != nil + && typeisstr(n.lhs.type_: *tinfo) + && typeisstr(n.rhs.type_: *tinfo)) { + cgstreqpush(c, n.rhs); + cgstreqpush(c, n.lhs); + emitline("\tPOPQ\tDI\n\tPOPQ\tSI\n\tPOPQ\tDX\n\tPOPQ\tCX\n"); + emitline("\tCALL\trt_streq(SB)\n"); + if (n.op == tkind.TK_NEQ) { emitline("\tXORQ\t$1, AX\n"); }; + return; + }; + let unsignd: bool = nodeisunsigned(c, n.lhs); if (!unsignd) { unsignd = nodeisunsigned(c, n.rhs); }; diff --git a/selfhost/cmd/wwdump/main.combined.ww b/selfhost/cmd/wwdump/main.combined.ww index 623be831..4462b267 100644 --- a/selfhost/cmd/wwdump/main.combined.ww +++ b/selfhost/cmd/wwdump/main.combined.ww @@ -26856,6 +26856,43 @@ fn cgun(c: *cgen, n: *node) void = { return; }; +// cgstreqpush — push one str operand's (len, then ptr) header words for +// the rt_streq content-compare in cgbin. Mirrors cstage cgen.c:4568-4615: +// an ident loads its 2-word header (ptr+len, NOT cap) from name(SB) for a +// module-global str (#154 let_islet branch) or BP+off for a local; a +// non-ident evals via cgexpr (AX=ptr, BX=len) and pushes BX then AX. Push +// order is len then ptr so the matching POPQ pops ptr first. +fn cgstreqpush(c: *cgen, op: *node) void = { + if (op.kind == nkind.N_IDENT) { + let nm: str = op.str; + let lc: *local = localfindnode(c, nm); + if (lc == nil && isletvar(c, nm)) { + emitline("\tLEAQ\t"); + emitsymnamehint(c, nm, c.curmod); + emitline("(SB), BX\n"); + emitline("\tMOVQ\t8(BX), AX\n"); + emitline("\tPUSHQ\tAX\n"); + emitline("\tMOVQ\t(BX), AX\n"); + emitline("\tPUSHQ\tAX\n"); + return; + }; + let off: i32 = 0; + if (lc != nil) { off = lc.off; }; + emitline("\tMOVQ\t"); + emitoff((off + 8): i64); + emitline("(BP), AX\n"); + emitline("\tPUSHQ\tAX\n"); + emitline("\tMOVQ\t"); + emitoff(off: i64); + emitline("(BP), AX\n"); + emitline("\tPUSHQ\tAX\n"); + return; + }; + cgexpr(c, op); + emitline("\tPUSHQ\tBX\n"); + emitline("\tPUSHQ\tAX\n"); +}; + fn cgbin(c: *cgen, n: *node) void = { // Short-circuit `&&` / `||`. Operands are bool (0/1); the type // checker enforces it. Eval LHS into AX, branch over RHS on the @@ -26877,6 +26914,26 @@ fn cgbin(c: *cgen, n: *node) void = { return; }; + // #146 (#154 ww-twin): str ==/!= is a CONTENT compare via rt_streq, + // not a ptr compare. Must run before the generic eager-eval tail + // below collapses each str header to its ptr word (AX). Push rhs + // then lhs (len, ptr each); POPQ DI/SI/DX/CX lands a.ptr,a.len, + // b.ptr,b.len per rt/streq.s; CALL rt_streq -> AX in {0,1}; XOR 1 + // for !=. The gate reads the checker stamp (typeisstr) exactly like + // cstage node_isstr. Byte-identical to cstage cbinop (cmd/w6c/ + // cgen.c:4564-4623). cstage was fixed by #154; this is its mirror. + if ((n.op == tkind.TK_EQ || n.op == tkind.TK_NEQ) + && n.lhs != nil && n.rhs != nil + && typeisstr(n.lhs.type_: *tinfo) + && typeisstr(n.rhs.type_: *tinfo)) { + cgstreqpush(c, n.rhs); + cgstreqpush(c, n.lhs); + emitline("\tPOPQ\tDI\n\tPOPQ\tSI\n\tPOPQ\tDX\n\tPOPQ\tCX\n"); + emitline("\tCALL\trt_streq(SB)\n"); + if (n.op == tkind.TK_NEQ) { emitline("\tXORQ\t$1, AX\n"); }; + return; + }; + let unsignd: bool = nodeisunsigned(c, n.lhs); if (!unsignd) { unsignd = nodeisunsigned(c, n.rhs); }; diff --git a/test/wcc/827_str_eq.c b/test/wcc/827_str_eq.c new file mode 100644 index 00000000..d63b0b7e --- /dev/null +++ b/test/wcc/827_str_eq.c @@ -0,0 +1,315 @@ +/* + * 827_str_eq — str `==` / `!=` is a CONTENT compare (rt_streq), not a + * pointer compare. #146 (the ww-twin of the #154 cstage fix). + * + * THE BUG (wwstage-only; cstage was already correct via #154): wwstage + * cgbin (selfhost/cmd/wcc/cgenexpr.ww) had NO str-awareness, so every + * `==`/`!=` fell to the generic comparison tail — a single `CMPQ BX, AX` + * on the eager-eval'd registers. For a str, eager-eval collapses the + * 3-word header to its ptr word, so the compare became ptr-vs-ptr: two + * DISTINCT-pointer equal-content strings answered FALSE on wwstage while + * cstage (which CALLs rt_streq) answered TRUE. THE divergence row is + * eq_dup_true: `let a="abc"; let b=strings.dup("abc"); a==b`. + * + * THE FIX: cgbin now has a str ==/!= branch at the top (before the + * generic eval), mirroring cstage cgen.c cbinop:4564-4623 — push rhs + * then lhs (len, ptr each), POPQ DI/SI/DX/CX = a.ptr,a.len,b.ptr,b.len + * (rt/streq.s ABI), CALL rt_streq -> AX in {0,1}, XORQ $1 for !=. + * + * Two row sets: + * runrows — built+RUN on BOTH drivers (need strings.dup for a + * distinct-pointer copy, so they `import strings` and build + * via `ww` which links the lib). These pin RUNTIME + * correctness; eq_dup_true/ne_dup_false are mutation-sane + * (pre-fix wwstage gave the wrong ptr-compare answer). + * asmrows — import-free single files run straight through w6c / + * w6c_ww for the BYTE-ID headline (w6c compiles one file and + * can't resolve strings.dup, so the import rows can't be + * byte-id'd directly; these import-free str==/!= sources + * exercise the identical cgbin branch and pin cs==ww `.s`). + * + * runrows | want + * -------------------------------------------------+------ + * eq_dup_true a=="abc", b=dup("abc"); a==b | 1 (THE bug) + * ne_dup_false a=="abc", b=dup("abc"); a!=b | 0 (!= twin) + * diff_content "abc"=="abd" | 0 (control) + * eq_self a="x"; a==a | 1 (same ptr) + * empty a="", b=dup(""); a==b | 1 (len-0 edge) + */ +#include +#include +#include +#include +#include +#include + +static int +runwait(const char *cmd) +{ + int rc = system(cmd); + if (rc == -1) return -1; + if (WIFEXITED(rc)) return WEXITSTATUS(rc); + return -1; +} + +struct row { const char *label; const char *src; int want; }; + +static const struct row runrows[] = { + /* eq_dup_true — THE regression pin: distinct pointer, equal + * content. Pre-fix wwstage ptr-compared -> 0 (WRONG); cstage + * CALLs rt_streq -> 1. */ + { "eq_dup_true", + "package main;\n" + "import strings;\n" + "export fn main() i32 = {\n" + "\tlet a: str = \"abc\";\n" + "\tlet b: str = strings.dup(\"abc\");\n" + "\tif (a == b) { return 1; };\n" + "\treturn 0;\n" + "};\n", + 1 }, + + /* ne_dup_false — the != twin: distinct pointer, equal content, so + * `!=` is FALSE. Pre-fix wwstage ptr-compared -> != true (WRONG). */ + { "ne_dup_false", + "package main;\n" + "import strings;\n" + "export fn main() i32 = {\n" + "\tlet a: str = \"abc\";\n" + "\tlet b: str = strings.dup(\"abc\");\n" + "\tif (a != b) { return 1; };\n" + "\treturn 0;\n" + "};\n", + 0 }, + + /* diff_content — distinct content; both stages agree (control). */ + { "diff_content", + "package main;\n" + "export fn main() i32 = {\n" + "\tif (\"abc\" == \"abd\") { return 1; };\n" + "\treturn 0;\n" + "};\n", + 0 }, + + /* eq_self — same pointer, equal content; both stages agree. */ + { "eq_self", + "package main;\n" + "export fn main() i32 = {\n" + "\tlet a: str = \"x\";\n" + "\tif (a == a) { return 1; };\n" + "\treturn 0;\n" + "};\n", + 1 }, + + /* empty — len-0 edge: rt_streq must match two empty strings. */ + { "empty", + "package main;\n" + "import strings;\n" + "export fn main() i32 = {\n" + "\tlet a: str = \"\";\n" + "\tlet b: str = strings.dup(\"\");\n" + "\tif (a == b) { return 1; };\n" + "\treturn 0;\n" + "};\n", + 1 }, +}; + +/* Import-free sources for the byte-id pass (w6c compiles a single file + * and can't resolve cross-module strings.dup). Each exercises the cgbin + * str ==/!= branch; the `.s` must be identical cstage vs wwstage. */ +static const struct row asmrows[] = { + /* be_eq_local — local str == local str (ident operand load). */ + { "be_eq_local", + "package main;\n" + "export fn main() i32 = {\n" + "\tlet a: str = \"abc\";\n" + "\tlet b: str = \"abd\";\n" + "\tif (a == b) { return 1; };\n" + "\treturn 0;\n" + "};\n", + 0 }, + + /* be_ne_local — the != twin (pins the XORQ $1, AX). */ + { "be_ne_local", + "package main;\n" + "export fn main() i32 = {\n" + "\tlet a: str = \"abc\";\n" + "\tlet b: str = \"abd\";\n" + "\tif (a != b) { return 1; };\n" + "\treturn 0;\n" + "};\n", + 1 }, + + /* be_eq_strlit — strlit == strlit (non-ident cgexpr operand). */ + { "be_eq_strlit", + "package main;\n" + "export fn main() i32 = {\n" + "\tif (\"abc\" == \"abc\") { return 1; };\n" + "\treturn 0;\n" + "};\n", + 1 }, + + /* be_eq_global — module-GLOBAL str == global str. This is the + * raison d'etre of the typeisstr gate (vs the spec's nodeisstr, + * whose N_IDENT arm keys on localfindnode and returns false for a + * global, leaving a latent cs!=ww hole). The cgstreqpush global arm + * (LEAQ name(SB)) must byte-match cstage's #154 let_islet branch. */ + { "be_eq_global", + "package main;\n" + "let g: str = \"abc\";\n" + "let h: str = \"abd\";\n" + "export fn main() i32 = {\n" + "\tif (g == h) { return 1; };\n" + "\treturn 0;\n" + "};\n", + 0 }, +}; + +static int +run_driver(const char *driver, const struct row *r, int i) +{ + char src[64], tmpdir[64], cmd[1024]; + snprintf(src, sizeof src, "/tmp/seq_%d_%d.ww", getpid(), i); + snprintf(tmpdir, sizeof tmpdir, "/tmp/seq_%d_d_%d", getpid(), i); + + FILE *f = fopen(src, "wb"); + if (!f) return -1; + fputs(r->src, f); + fclose(f); + + mkdir(tmpdir, 0755); + snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", + tmpdir, driver, src); + if (runwait(cmd) != 0) { + fprintf(stderr, "row[%s]: build via %s failed\n", + r->label, driver); + unlink(src); rmdir(tmpdir); + return -1; + } + + const char *base = strrchr(src, '/'); + base = base ? base + 1 : src; + char outbin[128]; + snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); + char *dot = strrchr(outbin, '.'); + if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; + int got = runwait(outbin); + + unlink(src); unlink(outbin); rmdir(tmpdir); + return got; +} + +/* asm_byte_identical — w6c vs w6c_ww .s for the same source must match. */ +static int +asm_byte_identical(const char *bin, const struct row *r, int i) +{ + char src[64], cs[64], ws[64], cmd[1024]; + snprintf(src, sizeof src, "/tmp/seq_asm_%d_%d.ww", getpid(), i); + snprintf(cs, sizeof cs, "/tmp/seq_asm_%d_%d_c.s", getpid(), i); + snprintf(ws, sizeof ws, "/tmp/seq_asm_%d_%d_w.s", getpid(), i); + + FILE *f = fopen(src, "wb"); + if (!f) return -1; + fputs(r->src, f); + fclose(f); + + snprintf(cmd, sizeof cmd, "%s/w6c -o %s %s 2>/dev/null", bin, cs, src); + if (runwait(cmd) != 0) { + fprintf(stderr, "row[%s]: w6c errored\n", r->label); + unlink(src); + return -1; + } + snprintf(cmd, sizeof cmd, "%s/w6c_ww -o %s %s 2>/dev/null", + bin, ws, src); + if (runwait(cmd) != 0) { + fprintf(stderr, "row[%s]: w6c_ww errored\n", r->label); + unlink(src); unlink(cs); + return -1; + } + + FILE *fc = fopen(cs, "rb"); + FILE *fw = fopen(ws, "rb"); + int rc = 0; + if (!fc || !fw) { + rc = -1; + } else { + for (;;) { + int a = fgetc(fc); + int b = fgetc(fw); + if (a != b) { rc = -1; break; } + if (a == EOF) break; + } + } + if (fc) fclose(fc); + if (fw) fclose(fw); + if (rc != 0) + fprintf(stderr, "row[%s]: cstage vs wwstage asm differs\n", + r->label); + unlink(src); unlink(cs); unlink(ws); + return rc; +} + +int +main(void) +{ + const char *bin = getenv("BIN"); + if (!bin) bin = "out/bin"; + char absbin[1024]; + if (bin[0] != '/') { + char cwd[1024]; + if (getcwd(cwd, sizeof cwd) == NULL) return 1; + snprintf(absbin, sizeof absbin, "%s/%s", cwd, bin); + bin = absbin; + } + + char cdrv[1024]; + snprintf(cdrv, sizeof cdrv, "%s/ww", bin); + char wdrv[1024]; + snprintf(wdrv, sizeof wdrv, "%s/ww_ww", bin); + + struct { const char *name; const char *path; int gated_on_existence; } + drivers[] = { + { "cstage", cdrv, 0 }, + { "wwstage", wdrv, 1 }, + { NULL, NULL, 0 }, + }; + + int nrun = (int)(sizeof runrows / sizeof runrows[0]); + int nasm = (int)(sizeof asmrows / sizeof asmrows[0]); + int total = 0, fail = 0; + + for (int d = 0; drivers[d].name; d++) { + if (drivers[d].gated_on_existence + && access(drivers[d].path, X_OK) != 0) { + fprintf(stderr, "str_eq: skip %s (no %s)\n", + drivers[d].name, drivers[d].path); + continue; + } + for (int i = 0; i < nrun; i++) { + int got = run_driver(drivers[d].path, &runrows[i], i); + total++; + if (got != runrows[i].want) { + fprintf(stderr, + "str_eq[%s][%s]: exit=%d want=%d\n", + drivers[d].name, runrows[i].label, + got, runrows[i].want); + fail++; + } + } + } + + if (access(wdrv, X_OK) == 0) { + for (int i = 0; i < nasm; i++) { + total++; + if (asm_byte_identical(bin, &asmrows[i], i) != 0) + fail++; + } + } + + if (fail) { + fprintf(stderr, "str_eq: %d/%d fixtures failed\n", fail, total); + return 1; + } + printf("str_eq: %d/%d ok\n", total, total); + return 0; +} diff --git a/test/wcc/989_lib_byteid.c b/test/wcc/989_lib_byteid.c index 2a7e00a5..23f7759a 100644 --- a/test/wcc/989_lib_byteid.c +++ b/test/wcc/989_lib_byteid.c @@ -133,7 +133,7 @@ static const struct ent ents[] = { .mode = M_ID, .sentinel = "package libc;", .moddir = "lib/c/libc" }, /* -------- documented-allowed cs≠ww (task #59) ------------ */ { .fixture = "lib/ascii/asciitest.ww", - .mode = M_DIVERGE, .cite = "#59.1" }, + .mode = M_ID, .cite = "#59.1 graduated by #146 str==" }, /* #59.2 bufio graduated to M_ID above (#129 fix) */ { .fixture = "lib/encoding/base64/base64_test.ww", .mode = M_DIVERGE, .cite = "#59.3" }, @@ -148,10 +148,10 @@ static const struct ent ents[] = { .mode = M_DIVERGE, .cite = "#59.9" }, /* #59.10 stoftest graduated to M_ID above (#62 fix) */ { .fixture = "lib/ww/lex/toktest.ww", - .mode = M_DIVERGE, .cite = "#59.11" }, + .mode = M_ID, .cite = "#59.11 graduated by #146 str==" }, /* asttest resolves `import tok` via -I lib/ww/lex, cf 905 */ { .fixture = "lib/ww/asttest.ww", .inc = "lib/ww/lex", - .mode = M_DIVERGE, .cite = "#59.12" }, + .mode = M_ID, .cite = "#59.12 graduated by #146 str==" }, /* -------- wwstage front-end gaps (task #59) -------------- */ { .fixture = "lib/crypto/sha256/sha256_test.ww", .mode = M_WWREJECT, .cite = "#59.13" },