Repository navigation
offsetof[T](field): target layout offsets; the migrator stops folding host offsets (D109, #2131) - #2266
Merged
Conversation
…ells C's offsetof with it (D109, #2131) The migrated pcre2 carried clang's host-folded offsetof values (136, 80, 120, 8 and the serialize offsets) as literals, so on wasm32 every heap frame was addressed askew and every match failed. offsetof[T](field) is a builtin beside sizeof: Sema resolves the field and records its index, codegen reads the target layout. The migrator emits it in bodies, initializers, object macros and uses of offsetof macros by name, through typedefs and macro-suffixed record names, with member chains summed. Offsetof checks read macros through a cache-free peek: the lookup's caches feed the literal fallback, and using them changed how unrelated macros translated (#2265). The four corpora are regenerated; only offsetof sites change.
…rator names c_import's flexible-array field (D109, #2131) The battery found three gaps. A module's runtime initializer (pcre2's HEAPFRAME_ALIGNMENT, compiled from source for Windows) resolves no names in codegen, so the record type is now Sema's fact per call node (offsetof_owner_in_body). The C emitter lowers offsetof to TypeLayout's offset, which its struct static-asserts already check. c_import renames a trailing [0]/[1] array to _name beside its accessor, so offsetof names that field.
Contributor
Author
|
Battery GREEN on b3acda6 (gate, uat, battery-checks: fixpoint, drop and move audits, every test target). The first battery on d158370 was red on three gaps, fixed in b3acda6: offsetof in a module's runtime initializer (Sema now records the measured record per call), emit-c lowering, and c_import's renamed flexible-array field. |
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.
offsetof[T](field)is a builtin besidesizeof[T](): the byte offset of a field in the compilation target's layout (D109, delegated; spec v7.29 §16.12). The C migrator spells C'soffsetof(T, f)with it instead of clang's host-folded number.Why (#2131 item 4). The migrated pcre2 carried
offsetof(heapframe, ovector)as 136,offsetof(heapframe, eptr)as 80,offsetof(pcre2_match_data, ovector)as 120 andHEAPFRAME_ALIGNMENTas 8: 64-bit host layouts. On wasm32 every heap frame was addressed askew and every regex match returned "no match".What changed
offsetof[T](field)resolves the field by name and records its index; MIR lowers no operand; codegen reads the layout model.(offsetof[T](f) as usize)in bodies, initializers, object macros and uses of offsetof macros by name; records resolve through typedefs and macro-suffixed names;offsetof(T, a.b)is a sum; an index designator stays loud.Evidence
test/behavior/behav_2131_offsetof.wfails on main, passes here; wasm32 gives 4/8 where native gives 8/16.c-migrator-basic-tests(body, initializer, macro, macro-named typedef, nested designator) migrates and runs.aona→ rc=1 span 0..1,[0-9]+onx42→ span 1..3; std.regex probe printstrue false true, same as native.audit:resolutionok on the test.