Repository navigation
migrate: C's {0} on a record and memset-to-zero of a record are T.zeroed() (D101, #2214) - #2229
Merged
Merged
Conversation
…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.
…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.
Contributor
Author
|
Battery GREEN on stack top bfecc6f (seed-driven, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A whole-record zero initializer prints
T.zeroed()(wasT { }over migrator-written field defaults, now refused by §4.3 rule 2); the assignment form printsx = T.zeroed()instead of awith_memset;memset(&x, 0, sizeof x)(andsizeof *p/sizeof(T)through a pointer) on a record isx = T.zeroed(). Other bytes, sizes and non-records staywith_memset. A record that is not zero-valid is refused at lowering naming the field (mirrors Sema's D101 rule). Codegen foldsT.zeroed()to zero data so a migratedstatic 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.