Skip to content

Commit

Permalink
components: fix trampoline compilation for lists. (bytecodealliance#4579
Browse files Browse the repository at this point in the history
)

This commit fixes trampoline compilation for lists where the loop condition
would only branch if the amount remaining was 0 instead of not 0.

It resulted in only the first element of the list being copied.
  • Loading branch information
peterhuene authored Aug 2, 2022
1 parent 8dddd6f commit 43125aa
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion crates/environ/src/fact/trampoline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,7 @@ impl Compiler<'_, '_> {
let src_add = if src_opts.memory64 { I64Add } else { I32Add };
let dst_add = if dst_opts.memory64 { I64Add } else { I32Add };
let src_eqz = if src_opts.memory64 { I64Eqz } else { I32Eqz };
let src_ne = if src_opts.memory64 { I64Ne } else { I32Ne };

// This block encompasses the entire loop and is use to exit before even
// entering the loop if the list size is zero.
Expand Down Expand Up @@ -887,7 +888,8 @@ impl Compiler<'_, '_> {
self.instruction(iconst(-1, src_opts.ptr()));
self.instruction(src_add.clone());
self.instruction(LocalTee(remaining));
self.instruction(src_eqz.clone());
self.instruction(iconst(0, src_opts.ptr()));
self.instruction(src_ne.clone());
self.instruction(BrIf(0));
self.instruction(End); // end of loop
self.instruction(End); // end of block
Expand Down

0 comments on commit 43125aa

Please sign in to comment.