Ensure WASM code gen uses proper tag ID alignment

We should use the alignment of the tag ID layout, not the alignment of
the rest of the data in the tag union. The reason is that the tag ID may
be smaller than the data.
This commit is contained in:
ayazhafiz 2021-12-26 17:45:05 -06:00
parent 235d6a9e88
commit 326bfe9aa3

View file

@ -830,7 +830,9 @@ impl<'a> WasmBackend<'a> {
// Store the tag ID (if any)
if stores_tag_id_as_data {
let id_offset = data_offset + data_size - data_alignment;
let id_align = Align::from(data_alignment);
let id_align = union_layout.tag_id_builtin().alignment_bytes(PTR_SIZE);
let id_align = Align::from(id_align);
self.code_builder.get_local(local_id);
@ -912,7 +914,9 @@ impl<'a> WasmBackend<'a> {
if union_layout.stores_tag_id_as_data(PTR_SIZE) {
let (data_size, data_alignment) = union_layout.data_size_and_alignment(PTR_SIZE);
let id_offset = data_size - data_alignment;
let id_align = Align::from(data_alignment);
let id_align = union_layout.tag_id_builtin().alignment_bytes(PTR_SIZE);
let id_align = Align::from(id_align);
self.storage
.load_symbols(&mut self.code_builder, &[structure]);