Преглед на файлове

* moved the 'end_block' WebAssembly instruction before the 'exit' label right
before the procedure finalization code. This fixes compilation errors in
procedures with implicit finalization code (e.g. for ansistring local vars,
etc).

Nikolay Nikolov преди 3 години
родител
ревизия
c96e203780
променени са 3 файла, в които са добавени 20 реда и са изтрити 7 реда
  1. 10 3
      compiler/psub.pas
  2. 10 2
      compiler/wasm32/cpupi.pas
  3. 0 2
      compiler/wasm32/hlcgcpu.pas

+ 10 - 3
compiler/psub.pas

@@ -29,7 +29,7 @@ interface
 
     uses
       globals,cclasses,
-      node,nbas,nutils,
+      node,nbas,nutils,aasmdata,
       symdef,procinfo,optdfa;
 
     type
@@ -74,6 +74,7 @@ interface
         procedure generate_code;
         procedure generate_code_tree;
         procedure generate_exceptfilter(nestedpi: tcgprocinfo);
+        procedure generate_exit_label(list: tasmlist); virtual;
         procedure resetprocdef;
         procedure add_to_symtablestack;
         procedure remove_from_symtablestack;
@@ -122,7 +123,7 @@ implementation
        cutils, cmsgs,
        { global }
        globtype,tokens,verbose,comphook,constexp,
-       systems,cpubase,aasmbase,aasmtai,aasmdata,
+       systems,cpubase,aasmbase,aasmtai,
        { symtable }
        symconst,symbase,symsym,symtype,symtable,defutil,defcmp,symcreat,
        paramgr,
@@ -1700,6 +1701,12 @@ implementation
       end;
 
 
+    procedure tcgprocinfo.generate_exit_label(list: tasmlist);
+      begin
+        hlcg.a_label(list,CurrExitLabel);
+      end;
+
+
      procedure TCGProcinfo.CreateInlineInfo;
        begin
         new(procdef.inlininginfo);
@@ -2058,7 +2065,7 @@ implementation
                 aktproccode.concatlist(templist);
               end;
             { insert exit label at the correct position }
-            hlcg.a_label(templist,CurrExitLabel);
+            generate_exit_label(templist);
             if assigned(exitlabel_asmnode.currenttai) then
               aktproccode.insertlistafter(exitlabel_asmnode.currenttai,templist)
             else

+ 10 - 2
compiler/wasm32/cpupi.pas

@@ -26,7 +26,7 @@ unit cpupi;
 interface
 
   uses
-    cutils,globtype,
+    cutils,globtype,aasmdata,
     procinfo,cpuinfo, symtype,aasmbase,cgbase,
     psub, cclasses;
 
@@ -38,6 +38,7 @@ interface
     public
       function calc_stackframe_size : longint;override;
       procedure setup_eh; override;
+      procedure generate_exit_label(list: tasmlist); override;
       procedure postprocess_code; override;
       procedure set_first_temp_offset;override;
     end;
@@ -45,7 +46,7 @@ interface
 implementation
 
     uses
-      systems,verbose,globals,cpubase,tgcpu,aasmdata,aasmcpu,aasmtai,cgexcept,
+      systems,verbose,globals,cpubase,tgcpu,aasmcpu,aasmtai,cgexcept,
       tgobj,paramgr,symconst,symdef,symtable,symcpu,cgutils,pass_2,parabase,
       fmodule,hlcgobj,hlcgcpu,defutil;
 
@@ -336,6 +337,13 @@ implementation
           internalerror(2021091701);
       end;
 
+    procedure tcpuprocinfo.generate_exit_label(list: tasmlist);
+      begin
+        list.concat(taicpu.op_none(a_end_block));
+        thlcgwasm(hlcg).decblock;
+        inherited generate_exit_label(list);
+      end;
+
     procedure tcpuprocinfo.postprocess_code;
 
       function findfirst_tai_functype(asmlist: TAsmList): tai_functype;

+ 0 - 2
compiler/wasm32/hlcgcpu.pas

@@ -2197,8 +2197,6 @@ implementation
 
   procedure thlcgwasm.gen_exit_code(list: TAsmList);
     begin
-      list.concat(taicpu.op_none(a_end_block));
-      decblock;
       if fevalstackheight<>0 then
 {$ifdef DEBUG_WASMSTACK}
         list.concat(tai_comment.Create(strpnew('!!! values remaining on stack at end of block !!!')));