Browse Source

+ disallow WebAssembly reference types in records, objects and classes

Nikolay Nikolov 2 years ago
parent
commit
fce34eb4bf

+ 2 - 1
compiler/msg/errore.msg

@@ -2119,7 +2119,7 @@ type_e_cannot_take_address_of_wasm_externref=04132_E_Cannot take the address of
 #
 # Symtable
 #
-# 05099 is the last used one
+# 05101 is the last used one
 #
 % \section{Symbol handling}
 % This section lists all the messages that concern the handling of symbols.
@@ -2443,6 +2443,7 @@ sym_e_symbol_no_capture=05099_E_Symbol "$1" can not be captured
 sym_f_systemunitnotloaded=05100_F_System unit not loaded.
 % The compiler used a function that requires the system unit to be loaded,
 % but it was not yet loaded. This is an internal compiler error and must be reported.
+sym_e_wasm_ref_types_cannot_be_used_in_records=05101_E_WebAssembly reference types cannot be used inside records, objects, or classes
 %
 % \end{description}
 #

+ 3 - 2
compiler/msgidx.inc

@@ -692,6 +692,7 @@ const
   sym_e_type_must_be_rec_or_object=05098;
   sym_e_symbol_no_capture=05099;
   sym_f_systemunitnotloaded=05100;
+  sym_e_wasm_ref_types_cannot_be_used_in_records=05101;
   cg_e_parasize_too_big=06009;
   cg_e_file_must_call_by_reference=06012;
   cg_e_cant_use_far_pointer_there=06013;
@@ -1165,9 +1166,9 @@ const
   option_info=11024;
   option_help_pages=11025;
 
-  MsgTxtSize = 91385;
+  MsgTxtSize = 91472;
 
   MsgIdxMax : array[1..20] of longint=(
-    28,109,369,133,101,63,148,38,223,71,
+    28,109,369,133,102,63,148,38,223,71,
     68,20,30,1,1,1,1,1,1,1
   );

File diff suppressed because it is too large
+ 452 - 453
compiler/msgtxt.inc


+ 5 - 1
compiler/pdecvar.pas

@@ -57,7 +57,7 @@ implementation
        systems,
        { symtable }
        symconst,symbase,defutil,defcmp,symutil,symcreat,
-{$if defined(i386) or defined(i8086)}
+{$if defined(i386) or defined(i8086) or defined(wasm)}
        symcpu,
 {$endif}
        fmodule,htypechk,procdefutil,
@@ -1779,6 +1779,10 @@ implementation
 
              read_anon_type(hdef,false);
              maybe_guarantee_record_typesym(hdef,symtablestack.top);
+{$ifdef wasm}
+             if is_wasm_reference_type(hdef) then
+               messagepos(typepos,sym_e_wasm_ref_types_cannot_be_used_in_records);
+{$endif wasm}
              block_type:=bt_var;
              { allow only static fields reference to struct where they are declared }
              if not (vd_class in options) then

+ 13 - 0
tests/test/wasm/twasmexternref5.pp

@@ -0,0 +1,13 @@
+{ %cpu=wasm32 }
+{ %fail }
+
+program twasmexternref5;
+
+type
+  TRec = record
+    { WebAssembly reference types cannot be used inside records, objects, or classes }
+    q: WasmExternRef;
+  end;
+
+begin
+end.

+ 13 - 0
tests/test/wasm/twasmexternref5a.pp

@@ -0,0 +1,13 @@
+{ %cpu=wasm32 }
+{ %fail }
+
+program twasmexternref5a;
+
+type
+  TRec = object
+    { WebAssembly reference types cannot be used inside records, objects, or classes }
+    q: WasmExternRef;
+  end;
+
+begin
+end.

+ 15 - 0
tests/test/wasm/twasmexternref5b.pp

@@ -0,0 +1,15 @@
+{ %cpu=wasm32 }
+{ %fail }
+
+program twasmexternref5b;
+
+{$MODE objfpc}
+
+type
+  TRec = class
+    { WebAssembly reference types cannot be used inside records, objects, or classes }
+    q: WasmExternRef;
+  end;
+
+begin
+end.

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

@@ -0,0 +1,14 @@
+{ %cpu=wasm32 }
+{ %fail }
+
+program twasmfuncref2;
+
+type
+  TWasmFuncRef = function(a: longint; b: int64): longint; WasmFuncRef;
+  TRec = record
+    { WebAssembly reference types cannot be used inside records, objects, or classes }
+    q: TWasmFuncRef;
+  end;
+
+begin
+end.

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

@@ -0,0 +1,14 @@
+{ %cpu=wasm32 }
+{ %fail }
+
+program twasmfuncref2a;
+
+type
+  TWasmFuncRef = function(a: longint; b: int64): longint; WasmFuncRef;
+  TRec = object
+    { WebAssembly reference types cannot be used inside records, objects, or classes }
+    q: TWasmFuncRef;
+  end;
+
+begin
+end.

+ 16 - 0
tests/test/wasm/twasmfuncref2b.pp

@@ -0,0 +1,16 @@
+{ %cpu=wasm32 }
+{ %fail }
+
+program twasmfuncref2b;
+
+{$MODE objfpc}
+
+type
+  TWasmFuncRef = function(a: longint; b: int64): longint; WasmFuncRef;
+  TRec = class
+    { WebAssembly reference types cannot be used inside records, objects, or classes }
+    q: TWasmFuncRef;
+  end;
+
+begin
+end.

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