Files
ww/test/lang/sret_narrow_field_test.ww
Hojun-Cho d8e7470555 test: migrate struct/sret round-trip family-7 to test/lang @test, retire C twins (fold-2)
Continue fold-2: migrate the struct-by-value / sret round-trip family from
bespoke build+run C twins to test/lang @test, retiring each twin in the same
commit. Runtime coverage MOVES from $(TESTS) to test-lang (T1 runs+asserts via
`ww test`) + test-lang-byteid (T2 keeps cs==ww .s byte-id); the $(TESTS)
headline drops 6. Every assert is a primitive int/u8/bool comparison (no
fmt/strconv in the assert path); each returned struct/tuple FIELD is asserted
individually so a dropped/mis-offset/over-wide word FAILS. 46 @test cases, a
strict superset of the 46 C rows (799=4, 925=10, 930=6, 949odd=7, 949chained=9,
949aggret=10).

  799_tuple_sret_receive_run.c   -> tuple_sret_receive_test.ww    (#10 Fold B: over-4-GP tuple `([]u8,[]u8)` sret RECEIVE — destructure/single-var/return-forward/reassign; len() only on destructured bindings, never len(t.N))
  925_sret_struct_return_run.c   -> sret_struct_return_test.ww     (#23: >24B sret round-trip; 32B/40B/nested/slice-payload, reassign-receive, struct16-by-value-arg #11 collision, N_IDENT return rhs, forward #9 simple/multi-arg/slice)
  930_sret_narrow_field_run.c    -> sret_narrow_field_test.ww      (#33: sret narrow trailing-field copy — bool/u8/i16/i32 + mixed bool+i32+i64 after the 24B slice)
  949_oddstruct_byval_ret_run.c  -> oddstruct_byval_ret_test.ww    (#107: by-value return of odd sub-8 size {3,5,6,7} single-eightbyte + 8/12/24 boundaries)
  949_chained_dot_struct_copy_run.c -> chained_dot_struct_copy_test.ww (#107 sibling: chained-DOT `t.m.l = s` natural-size tail copy {0..7} + via-CX global dest; neighbour z is the oracle)
  949_aggret_source_run.c        -> aggret_source_test.ww          (#272: aggregate return from every addressable source — arrlit/N_DOT/N_INDEX/deref/ident + >24B sret arm + global-receive caller-half)

This family is sret / struct-by-value-return (the #107/#38/#271/#272 ABI area):
all 6 new files are byte-id cs==ww (no fold-5 divergence surfaced). Bump
LANGBYTEID_EXPECTED_MIN 43->49 to ratchet the new corpus floor.
2026-06-22 13:52:41 +09:00

82 lines
2.0 KiB
Plaintext

// sret_narrow_field_test — sret callee's narrow trailing-field copy (#33),
// migrated from test/wcc/930_sret_narrow_field_run.c. A >24B struct that ends in
// a narrow primitive (bool / u8 / i16 / i32) must copy exactly that field's
// width; pre-fix cstage's N_IDENT word-copy tail used a slot-padded MOVQ that
// swept the bordering @sretarg save byte into the trailing field. Each @test
// asserts the trailing field round-trips as a primitive; T2 keeps the cs==ww net.
// The mixed row interleaves bool + i32 + i64 after the 24B slice payload so each
// trailing field must emit its declared width at its natural offset.
package sret_narrow_field_test;
type tbool = struct { a: i32, s: []u8, r: bool };
type tu8 = struct { a: i32, s: []u8, r: u8 };
type ti16 = struct { a: i32, s: []u8, r: i16 };
type ti32 = struct { a: i32, s: []u8, r: i32 };
type tmix = struct { s: []u8, r: bool, n: i32, k: i64 };
fn mk_bt() tbool = {
let v: tbool; let z: []u8;
v.s = z; v.a = 7; v.r = true;
return v;
};
fn mk_bf() tbool = {
let v: tbool; let z: []u8;
v.s = z; v.a = 9; v.r = false;
return v;
};
fn mk_u8() tu8 = {
let v: tu8; let z: []u8;
v.s = z; v.a = 0; v.r = 0xFFu8;
return v;
};
fn mk_i16() ti16 = {
let v: ti16; let z: []u8;
v.s = z; v.a = 0; v.r = -123i16;
return v;
};
fn mk_i32() ti32 = {
let v: ti32; let z: []u8;
v.s = z; v.a = 0; v.r = -424242;
return v;
};
fn mk_mix() tmix = {
let v: tmix; let z: []u8;
v.s = z; v.r = true; v.n = 1234567; v.k = 9876543210i64;
return v;
};
@test fn bool_true() void = {
let x: tbool = mk_bt();
assert(x.a == 7);
assert(x.r);
};
@test fn bool_false() void = {
let x: tbool = mk_bf();
assert(x.a == 9);
assert(!x.r);
};
@test fn u8_high_bit() void = {
let x: tu8 = mk_u8();
assert(x.r == 0xFFu8);
};
@test fn i16_negative() void = {
let x: ti16 = mk_i16();
assert(x.r == -123i16);
};
@test fn i32_negative() void = {
let x: ti32 = mk_i32();
assert(x.r == -424242);
};
@test fn mixed_narrow_after_slice() void = {
let x: tmix = mk_mix();
assert(x.r);
assert(x.n == 1234567);
assert(x.k == 9876543210i64);
};