+ disallow using sizeof() and bitsizeof() on WebAssembly reference types

This commit is contained in:
Nikolay Nikolov 2023-06-20 16:56:47 +03:00
parent edbb865260
commit 5c792c438d
10 changed files with 659 additions and 566 deletions

View File

@ -1656,7 +1656,7 @@ parser_e_suspending_externals_not_supported_on_current_platform=03368_E_Declarin
%
# Type Checking
#
# 04132 is the last used one
# 04133 is the last used one
#
% \section{Type checking errors}
% This section lists all errors that can occur when type checking is
@ -2114,6 +2114,8 @@ type_e_nested_procvar_to_funcref=04131_E_A nested function variable can not be a
% in design assigning a nested function variable to a function reference is forbidden.
type_e_cannot_take_address_of_wasm_externref=04132_E_Cannot take the address of a WebAssembly externref
% WebAssembly externref types don't have an in-memory representation and therefore, their address cannot be taken.
type_e_cannot_determine_size_of_wasm_reference_type=04133_E_WebAssembly reference types don't have an observable size
% WebAssembly reference types are opaque, meaning neither their size, nor their bit pattern can be observed.
%
% \end{description}
#

View File

@ -605,6 +605,7 @@ const
type_w_array_size_does_not_match_size_of_constant_string=04130;
type_e_nested_procvar_to_funcref=04131;
type_e_cannot_take_address_of_wasm_externref=04132;
type_e_cannot_determine_size_of_wasm_reference_type=04133;
sym_e_id_not_found=05000;
sym_f_internal_error_in_symtablestack=05001;
sym_e_duplicate_id=05002;
@ -1166,9 +1167,9 @@ const
option_info=11024;
option_help_pages=11025;
MsgTxtSize = 91472;
MsgTxtSize = 91538;
MsgIdxMax : array[1..20] of longint=(
28,109,369,133,102,63,148,38,223,71,
28,109,369,134,102,63,148,38,223,71,
68,20,30,1,1,1,1,1,1,1
);

File diff suppressed because it is too large Load Diff

View File

@ -457,8 +457,13 @@ implementation
{ allow helpers for SizeOf and BitSizeOf }
if p1.nodetype=typen then
ttypenode(p1).helperallowed:=true;
//Writeln(p1.nodetype, p1.resultdef.typ);
if (p1.resultdef.typ=forwarddef) then
Message1(type_e_type_is_not_completly_defined,tforwarddef(p1.resultdef).tosymname^);
{$ifdef wasm}
if is_wasm_reference_type(p1.resultdef) then
Message(type_e_cannot_determine_size_of_wasm_reference_type);
{$endif wasm}
if (l = in_sizeof_x) or
(not((p1.nodetype = vecn) and
is_packed_array(tvecnode(p1).left.resultdef)) and

View File

@ -0,0 +1,11 @@
{ %cpu=wasm32 }
{ %fail }
program twasmexternref6;
const
{ Cannot take the size of WebAssembly reference types }
Q = SizeOf(WasmExternRef);
begin
end.

View File

@ -0,0 +1,11 @@
{ %cpu=wasm32 }
{ %fail }
program twasmexternref6a;
const
{ Cannot take the size of WebAssembly reference types }
Q = BitSizeOf(WasmExternRef);
begin
end.

View File

@ -0,0 +1,15 @@
{ %cpu=wasm32 }
{ %fail }
program twasmexternref6b;
procedure test(para: WasmExternRef);
var
a: longint;
begin
{ Cannot take the size of WebAssembly reference types }
a := SizeOf(para);
end;
begin
end.

View File

@ -0,0 +1,14 @@
{ %cpu=wasm32 }
{ %fail }
program twasmfuncref3;
type
TWasmFuncRef = function(a: longint; b: int64): longint; WasmFuncRef;
const
{ Cannot take the size of WebAssembly reference types }
Q = SizeOf(TWasmFuncRef);
begin
end.

View File

@ -0,0 +1,14 @@
{ %cpu=wasm32 }
{ %fail }
program twasmfuncref3a;
type
TWasmFuncRef = function(a: longint; b: int64): longint; WasmFuncRef;
const
{ Cannot take the size of WebAssembly reference types }
Q = BitSizeOf(TWasmFuncRef);
begin
end.

View File

@ -0,0 +1,18 @@
{ %cpu=wasm32 }
{ %fail }
program twasmfuncref3b;
type
TWasmFuncRef = function(a: longint; b: int64): longint; WasmFuncRef;
procedure test(para: TWasmFuncRef);
var
a: longint;
begin
{ Cannot take the size of WebAssembly reference types }
a := SizeOf(para);
end;
begin
end.