Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
codegen: bitcast to expanded struct type when accessing its fields
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: struct foo { uint16_t a; //implicit padding of 2 bytes uint32_t b; }; struct bar { struct foo f; } It will actually become something like this: struct foo { uint16_t a; //implicit padding of 2 bytes uint32_t b; }; struct bar { uint16_t a; uint8_t _padding[2]; uint32_t b; } 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 for `foo`. 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
- Loading branch information