codegen: bitcast to expanded struct type when accessing its fields #209
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.
Cheerp, for structs, expands other structs that are in the first member position. During this expansion, for technical reasons, it explicitly already adds the padding to the expanded struct. So for structs like this:
It will actually become something like this:
However, accesses to the base struct's fields were not aware of this extra field being added, and falsely assuming that, for
bar
,b
would still be in the second position like it is forfoo
.The linear memory layout of these two types is, however, still exactly the same. The only difference for LLVM is that the implicit padding is already there.
Fixed this by bitcasting to the expanded struct type before trying to access its fields.
Closes: leaningtech/cheerp-meta#118
I've checked for the cheerp target, and it doesn't seem to be adding the padding like we might thought it would.
Please merge leaningtech/cheerp-utils#66 before this PR