浏览代码

* use create_functype to determine accurately the number of parameters to
discard in twasmcallnode.do_release_unused_return_value. This fixes
various stack tracking bugs when a constructor is invoking another
constructor, etc.

Nikolay Nikolov 3 年之前
父节点
当前提交
324382d3a5
共有 1 个文件被更改,包括 14 次插入7 次删除
  1. 14 7
      compiler/wasm32/nwasmcal.pas

+ 14 - 7
compiler/wasm32/nwasmcal.pas

@@ -49,7 +49,7 @@ interface
 implementation
 implementation
 
 
     uses
     uses
-      globtype, aasmdata, defutil, tgobj, hlcgcpu, symconst, paramgr;
+      globtype, aasmdata, defutil, tgobj, hlcgcpu, symconst, symcpu;
 
 
       { twasmcallnode }
       { twasmcallnode }
 
 
@@ -59,13 +59,20 @@ implementation
       end;
       end;
 
 
     procedure twasmcallnode.do_release_unused_return_value;
     procedure twasmcallnode.do_release_unused_return_value;
+      var
+        ft: TWasmFuncType;
+        i: Integer;
       begin
       begin
-        if is_void(resultdef) then
-          exit;
-        if paramanager.ret_in_param(resultdef,procdefinition) then
-          exit;
-        current_asmdata.CurrAsmList.concat(taicpu.op_none(a_drop));
-        thlcgwasm(hlcg).decstack(current_asmdata.CurrAsmList,1);
+        if procdefinition.typ=procvardef then
+          ft:=tcpuprocvardef(procdefinition).create_functype
+        else
+          ft:=tcpuprocdef(procdefinition).create_functype;
+        for i:=1 to Length(ft.results) do
+          begin
+            current_asmdata.CurrAsmList.concat(taicpu.op_none(a_drop));
+            thlcgwasm(hlcg).decstack(current_asmdata.CurrAsmList,1);
+          end;
+        ft.free;
       end;
       end;
 
 
     procedure twasmcallnode.set_result_location(realresdef: tstoreddef);
     procedure twasmcallnode.set_result_location(realresdef: tstoreddef);