Browse Source

* WebAssembly goto support: skip unused labels in resolve_labels_via_state_machine. Fixes #41093

Nikolay Nikolov 5 months ago
parent
commit
79b240ec81
2 changed files with 32 additions and 4 deletions
  1. 8 4
      compiler/wasm32/cpupi.pas
  2. 24 0
      tests/webtbs/tw41093.pp

+ 8 - 4
compiler/wasm32/cpupi.pas

@@ -714,10 +714,14 @@ implementation
                 asmlist.Remove(hp);
                 asmlist.Remove(hp);
                 if hp.typ=ait_label then
                 if hp.typ=ait_label then
                   begin
                   begin
-                    curr_block:=TAsmList.Create;
-                    blocks.Add(tai_label(hp).labsym.Name,curr_block);
-                  end;
-                curr_block.Concat(hp);
+                    if (tai_label(hp).labsym.is_used) then
+                      begin
+                        curr_block:=TAsmList.Create;
+                        blocks.Add(tai_label(hp).labsym.Name,curr_block);
+                      end;
+                  end
+                else
+                  curr_block.Concat(hp);
               end;
               end;
           until not assigned(hp);
           until not assigned(hp);
           { asmlist is now empty }
           { asmlist is now empty }

+ 24 - 0
tests/webtbs/tw41093.pp

@@ -0,0 +1,24 @@
+{ %OPT=-Sg }
+{$mode objfpc}
+{$H+}
+
+procedure Test;
+var
+  A: String;
+
+  function TestInline: Char; inline;
+  begin
+  end;
+
+label
+  TestLabel;
+
+begin
+  A := TestInline;
+  goto TestLabel;
+TestLabel:
+end;
+
+begin
+  Test;
+end.