@@ -550,11 +550,13 @@ fn instruction(js: &mut JsBuilder, instr: &Instruction, log_error: &mut bool) ->
550
550
| Instruction :: CallTableElement ( _)
551
551
| Instruction :: DeferCallCore ( _) => {
552
552
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 ) ;
554
554
555
555
let mut args = Vec :: new ( ) ;
556
556
let tmp = js. tmp ( ) ;
557
557
if invoc. defer ( ) {
558
+ // substract alignment
559
+ params -= 1 ;
558
560
// If the call is deferred, the arguments to the function still need to be
559
561
// accessible in the `finally` block, so we declare variables to hold the args
560
562
// 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) ->
564
566
writeln ! ( js. prelude, "{name} = {arg};" ) . unwrap ( ) ;
565
567
args. push ( name) ;
566
568
}
569
+ // add alignment
570
+ args. push ( String :: from ( "4" ) ) ;
567
571
} else {
568
572
// Otherwise, pop off the number of parameters for the function we're calling.
569
573
for _ in 0 ..params {
@@ -813,12 +817,14 @@ fn instruction(js: &mut JsBuilder, instr: &Instruction, log_error: &mut bool) ->
813
817
let func = js. cx . pass_to_wasm_function ( kind. clone ( ) , * mem) ?;
814
818
let malloc = js. cx . export_name_of ( * malloc) ;
815
819
let i = js. tmp ( ) ;
820
+ let align = std:: cmp:: max ( kind. size ( ) , 4 ) ;
816
821
js. prelude ( & format ! (
817
- "const ptr{i} = {f}({0}, wasm.{malloc});" ,
822
+ "const ptr{i} = {f}({0}, wasm.{malloc}, {align} );" ,
818
823
val,
819
824
i = i,
820
825
f = func,
821
826
malloc = malloc,
827
+ align = align,
822
828
) ) ;
823
829
js. prelude ( & format ! ( "const len{} = WASM_VECTOR_LEN;" , i) ) ;
824
830
js. push ( format ! ( "ptr{}" , i) ) ;
@@ -922,7 +928,7 @@ fn instruction(js: &mut JsBuilder, instr: &Instruction, log_error: &mut bool) ->
922
928
let malloc = js. cx . export_name_of ( * malloc) ;
923
929
let val = js. pop ( ) ;
924
930
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 );" ,
926
932
val,
927
933
i = i,
928
934
f = func,
@@ -940,7 +946,7 @@ fn instruction(js: &mut JsBuilder, instr: &Instruction, log_error: &mut bool) ->
940
946
let malloc = js. cx . export_name_of ( * malloc) ;
941
947
let i = js. tmp ( ) ;
942
948
js. prelude ( & format ! (
943
- "var ptr{i} = {f}({val}, wasm.{malloc});" ,
949
+ "var ptr{i} = {f}({val}, wasm.{malloc}, 4 );" ,
944
950
val = val,
945
951
i = i,
946
952
f = func,
0 commit comments