@@ -550,11 +550,13 @@ fn instruction(js: &mut JsBuilder, instr: &Instruction, log_error: &mut bool) ->
550550 | Instruction :: CallTableElement ( _)
551551 | Instruction :: DeferCallCore ( _) => {
552552 let invoc = Invocation :: from ( instr, js. cx . module ) ?;
553- let ( params, results) = invoc. params_results ( js. cx ) ;
553+ let ( mut params, results) = invoc. params_results ( js. cx ) ;
554554
555555 let mut args = Vec :: new ( ) ;
556556 let tmp = js. tmp ( ) ;
557557 if invoc. defer ( ) {
558+ // substract alignment
559+ params -= 1 ;
558560 // If the call is deferred, the arguments to the function still need to be
559561 // accessible in the `finally` block, so we declare variables to hold the args
560562 // outside of the try-finally block and then set those to the args.
@@ -564,6 +566,8 @@ fn instruction(js: &mut JsBuilder, instr: &Instruction, log_error: &mut bool) ->
564566 writeln ! ( js. prelude, "{name} = {arg};" ) . unwrap ( ) ;
565567 args. push ( name) ;
566568 }
569+ // add alignment
570+ args. push ( String :: from ( "4" ) ) ;
567571 } else {
568572 // Otherwise, pop off the number of parameters for the function we're calling.
569573 for _ in 0 ..params {
@@ -813,12 +817,14 @@ fn instruction(js: &mut JsBuilder, instr: &Instruction, log_error: &mut bool) ->
813817 let func = js. cx . pass_to_wasm_function ( kind. clone ( ) , * mem) ?;
814818 let malloc = js. cx . export_name_of ( * malloc) ;
815819 let i = js. tmp ( ) ;
820+ let align = std:: cmp:: max ( kind. size ( ) , 4 ) ;
816821 js. prelude ( & format ! (
817- "const ptr{i} = {f}({0}, wasm.{malloc});" ,
822+ "const ptr{i} = {f}({0}, wasm.{malloc}, {align} );" ,
818823 val,
819824 i = i,
820825 f = func,
821826 malloc = malloc,
827+ align = align,
822828 ) ) ;
823829 js. prelude ( & format ! ( "const len{} = WASM_VECTOR_LEN;" , i) ) ;
824830 js. push ( format ! ( "ptr{}" , i) ) ;
@@ -922,7 +928,7 @@ fn instruction(js: &mut JsBuilder, instr: &Instruction, log_error: &mut bool) ->
922928 let malloc = js. cx . export_name_of ( * malloc) ;
923929 let val = js. pop ( ) ;
924930 js. prelude ( & format ! (
925- "var ptr{i} = isLikeNone({0}) ? 0 : {f}({0}, wasm.{malloc});" ,
931+ "var ptr{i} = isLikeNone({0}) ? 0 : {f}({0}, wasm.{malloc}, 4 );" ,
926932 val,
927933 i = i,
928934 f = func,
@@ -940,7 +946,7 @@ fn instruction(js: &mut JsBuilder, instr: &Instruction, log_error: &mut bool) ->
940946 let malloc = js. cx . export_name_of ( * malloc) ;
941947 let i = js. tmp ( ) ;
942948 js. prelude ( & format ! (
943- "var ptr{i} = {f}({val}, wasm.{malloc});" ,
949+ "var ptr{i} = {f}({val}, wasm.{malloc}, 4 );" ,
944950 val = val,
945951 i = i,
946952 f = func,
0 commit comments