Skip to content

migrate: C's {0} on a record and memset-to-zero of a record are T.zeroed() (D101, #2214) - #2229

Merged
ehartford merged 2 commits into
str-helpersfrom
migrate-zeroed
Oct 7, 2026
Merged

ehartford merged 2 commits into
str-helpersfrom
migrate-zeroed

Conversation

@ehartford

@ehartford ehartford commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

A whole-record zero initializer prints T.zeroed() (was T { } over migrator-written field defaults, now refused by §4.3 rule 2); the assignment form prints x = T.zeroed() instead of a with_memset; memset(&x, 0, sizeof x) (and sizeof *p / sizeof(T) through a pointer) on a record is x = T.zeroed(). Other bytes, sizes and non-records stay with_memset. A record that is not zero-valid is refused at lowering naming the field (mirrors Sema's D101 rule). Codegen folds T.zeroed() to zero data so a migrated static struct P g = {0} is initialized storage in a bundle object. Fixture in c-migrator-basic-tests; corpora re-migrated.

Fixes #2214. Draft until the stack's battery is green.

…oed() (D101, #2214)

A whole-record zero initializer (`{0}`, `{}`) prints `T.zeroed()` instead
of `T {  }` (which leaned on migrator-written field defaults and now meets
§4.3 rule 2); the assignment form prints `x = T.zeroed()` instead of a
`with_memset` over the storage. `memset(p, 0, n)` where `p` is `&x` or a
pointer to a record and `n` is `sizeof x` / `sizeof *p` / `sizeof(T)` of
that record is the assignment `x = T.zeroed()` (through `*p` for a
pointer); a fill of another byte, another size or a non-record stays
`with_memset`. The lowering refuses, naming the field, when the record is
not zero-valid (`ci_record_zero_invalid_field` mirrors Sema's D101 rule
over the translated field texts) — never a partial literal.

Codegen folds `T.zeroed()` to the zero of its type as data, so a migrated
`static struct P g = {0}` is initialized storage in a bundle object (a
runtime init there is what #2219 now refuses).

Fixture `bs_check_migrate_zeroed_records` in c-migrator-basic-tests:
global, local, place memset, pointer memset, byte-array and non-zero
fills, and the output checks.
@ehartford
ehartford added this pull request to stack #2228 October 7, 2026 00:07
@ehartford ehartford changed the title migrate zeroed migrate: C's {0} on a record and memset-to-zero of a record are T.zeroed() (D101, #2214) Oct 7, 2026
…r (D101, #2214)

Every `T {  }` record zero and record-sized `with_memset` is `T.zeroed()`;
nothing else moved (c_algorithms unchanged). corpus-drift-check green;
pcre2-test, zlib and tommyds suites green under the promoted corpora.
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery GREEN on stack top bfecc6f (seed-driven, with run tools/battery.w): gate rc=0 399s, uat rc=0 28s, battery-checks rc=0 397s.

@ehartford
ehartford marked this pull request as ready for review October 7, 2026 02:14
@ehartford
ehartford merged commit 6ac1fb3 into main Oct 7, 2026
@ehartford
ehartford deleted the migrate-zeroed branch October 7, 2026 02:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

migrate: map {0} initializers and memset-to-zero to T.zeroed() (D101)

1 participant