Browse Source

* disallow WebAssembly reference types to be declared as var, constref or out parameters

Nikolay Nikolov 2 years ago
parent
commit
f670ebbb28

+ 2 - 1
compiler/msg/errore.msg

@@ -445,7 +445,7 @@ scan_e_unexpected_endif=02108_E_$ENDIF directive found without a matching $IF(N)
 #
 #
 # Parser
 # Parser
 #
 #
-# 03365 is the last used one
+# 03366 is the last used one
 #
 #
 % \section{Parser messages}
 % \section{Parser messages}
 % This section lists all parser messages. The parser takes care of the
 % This section lists all parser messages. The parser takes care of the
@@ -1644,6 +1644,7 @@ parser_w_ignoring_published_property=03365_W_This property will not be published
 % On a certain target, not all syntax variants of the syscall directive make sense and thus those making
 % On a certain target, not all syntax variants of the syscall directive make sense and thus those making
 % no sense are not supported
 % no sense are not supported
 % Declarations like \var{var i: Integer absolute i;} are not allowed
 % Declarations like \var{var i: Integer absolute i;} are not allowed
+parser_e_wasm_ref_types_can_only_be_passed_by_value=03366_E_WebAssembly reference types can only be passed by value
 %
 %
 % \end{description}
 % \end{description}
 %
 %

+ 3 - 2
compiler/msgidx.inc

@@ -479,6 +479,7 @@ const
   parser_e_absolute_sym_cannot_reference_itself=03363;
   parser_e_absolute_sym_cannot_reference_itself=03363;
   parser_e_syscall_format_not_support=03364;
   parser_e_syscall_format_not_support=03364;
   parser_w_ignoring_published_property=03365;
   parser_w_ignoring_published_property=03365;
+  parser_e_wasm_ref_types_can_only_be_passed_by_value=03366;
   type_e_mismatch=04000;
   type_e_mismatch=04000;
   type_e_incompatible_types=04001;
   type_e_incompatible_types=04001;
   type_e_not_equal_types=04002;
   type_e_not_equal_types=04002;
@@ -1158,9 +1159,9 @@ const
   option_info=11024;
   option_info=11024;
   option_help_pages=11025;
   option_help_pages=11025;
 
 
-  MsgTxtSize = 90677;
+  MsgTxtSize = 90741;
 
 
   MsgIdxMax : array[1..20] of longint=(
   MsgIdxMax : array[1..20] of longint=(
-    28,109,366,133,100,63,148,38,223,71,
+    28,109,367,133,100,63,148,38,223,71,
     65,20,30,1,1,1,1,1,1,1
     65,20,30,1,1,1,1,1,1,1
   );
   );

File diff suppressed because it is too large
+ 382 - 383
compiler/msgtxt.inc


+ 4 - 0
compiler/pdecsub.pas

@@ -510,6 +510,10 @@ implementation
                     if explicit_paraloc then
                     if explicit_paraloc then
                       Message(parser_e_paraloc_all_paras);
                       Message(parser_e_paraloc_all_paras);
                 end;
                 end;
+{$ifdef wasm}
+              if (vs.varspez in [vs_var,vs_constref,vs_out]) and is_wasm_reference_type(vs.vardef) then
+                Message(parser_e_wasm_ref_types_can_only_be_passed_by_value);
+{$endif wasm}
             end;
             end;
         until not try_to_consume(_SEMICOLON);
         until not try_to_consume(_SEMICOLON);
 
 

+ 4 - 0
tests/test/wasm/twasmexternref1.pp

@@ -43,6 +43,10 @@ begin
   testproc6 := nil <> q;
   testproc6 := nil <> q;
 end;
 end;
 
 
+procedure testproc7(const q: WasmExternRef);
+begin
+end;
+
 begin
 begin
   testproc5(nil);
   testproc5(nil);
 end.
 end.

+ 12 - 0
tests/test/wasm/twasmexternref4.pp

@@ -0,0 +1,12 @@
+{ %cpu=wasm32 }
+{ %fail }
+
+program twasmexternref4;
+
+{ WasmExternRef cannot be declared a var parameter }
+procedure testproc(var p: WasmExternRef);
+begin
+end;
+
+begin
+end.

+ 12 - 0
tests/test/wasm/twasmexternref4a.pp

@@ -0,0 +1,12 @@
+{ %cpu=wasm32 }
+{ %fail }
+
+program twasmexternref4a;
+
+{ WasmExternRef cannot be declared a constref parameter }
+procedure testproc(constref p: WasmExternRef);
+begin
+end;
+
+begin
+end.

+ 14 - 0
tests/test/wasm/twasmexternref4b.pp

@@ -0,0 +1,14 @@
+{ %cpu=wasm32 }
+{ %fail }
+
+program twasmexternref4a;
+
+{$MODE objfpc}
+
+{ WasmExternRef cannot be declared an out parameter }
+procedure testproc(out p: WasmExternRef);
+begin
+end;
+
+begin
+end.

Some files were not shown because too many files changed in this diff