+ disallow taking the address of WebAssembly externref type

This commit is contained in:
Nikolay Nikolov 2023-06-11 04:00:45 +03:00
parent 65b175cebd
commit 8743f72f11
6 changed files with 612 additions and 530 deletions

View File

@ -1649,7 +1649,7 @@ parser_w_ignoring_published_property=03365_W_This property will not be published
%
# Type Checking
#
# 04131 is the last used one
# 04132 is the last used one
#
% \section{Type checking errors}
% This section lists all errors that can occur when type checking is
@ -2105,6 +2105,8 @@ type_e_nested_procvar_to_funcref=04131_E_A nested function variable can not be a
% Function references can live beyond the scope of the function they're contained in while
% nested functions assigned to nested function variables can't. Due to this discrepancy
% 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.
%
% \end{description}
#

View File

@ -601,6 +601,7 @@ const
type_e_cant_read_write_type_in_iso_mode=04129;
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;
sym_e_id_not_found=05000;
sym_f_internal_error_in_symtablestack=05001;
sym_e_duplicate_id=05002;
@ -1157,9 +1158,9 @@ const
option_info=11024;
option_help_pages=11025;
MsgTxtSize = 90618;
MsgTxtSize = 90677;
MsgIdxMax : array[1..20] of longint=(
28,109,366,132,100,63,148,38,223,71,
28,109,366,133,100,63,148,38,223,71,
65,20,30,1,1,1,1,1,1,1
);

File diff suppressed because it is too large Load Diff

View File

@ -34,6 +34,7 @@ implementation
ncgadd, ncgcal,ncgmat,ncginl,
nwasmbas,nwasmadd,nwasmcal,nwasmmat,nwasmflw,nwasmcon,nwasmcnv,nwasmset,nwasminl,nwasmld,
nwasmmem,
{ these are not really nodes }
nwasmutil,
{ symtable }

View File

@ -0,0 +1,59 @@
{
Copyright (c) 1998-2023 by Florian Klaempfl and Nikolay Nikolov
Generate WebAssembly code for memory related nodes
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
****************************************************************************}
unit nwasmmem;
{$i fpcdefs.inc}
interface
uses
node,nmem,ncgmem;
type
{ twasmaddrnode }
twasmaddrnode = class(tcgaddrnode)
function pass_typecheck:tnode;override;
end;
implementation
uses
verbose,
symcpu;
{ twasmaddrnode }
function twasmaddrnode.pass_typecheck: tnode;
begin
Result:=inherited;
if is_wasm_externref(left.resultdef) then
begin
CGMessagePos(left.fileinfo,type_e_cannot_take_address_of_wasm_externref);
result:=nil;
exit;
end;
end;
begin
caddrnode:=twasmaddrnode;
end.

View File

@ -0,0 +1,16 @@
{ %cpu=wasm32 }
{ %fail }
program twasmexternref2;
procedure testproc;
var
p: WasmExternRef;
q: Pointer;
begin
{ WasmExternRef cannot be address taken }
q := @p;
end;
begin
end.