[PATCH] D139010: [clang][WebAssembly] Implement support for table types and builtins

Paulo Matos via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 20 05:35:17 PDT 2023


pmatos added inline comments.


================
Comment at: clang/test/SemaCXX/wasm-refs-and-tables.cpp:16-17
+__externref_t **t2;              // expected-error {{pointer to WebAssembly reference type is not allowed}}
+__externref_t ******t3;          // expected-error {{pointer to WebAssembly reference type is not allowed}}
+static __externref_t t4[3];      // expected-error {{only zero-length WebAssembly tables are currently supported}}
+static __externref_t t5[];       // expected-error {{only zero-length WebAssembly tables are currently supported}}
----------------
aaron.ballman wrote:
> This seems really... confused. We can't form a pointer to the type, but we can form an array of the type (which decays into a pointer when you sneeze near it, and it's not clear whether that should be allowed or not) so long as it's a zero-length array (which is an extension in C and C++, so do we need to silence pedantic warnings in WASM for this?).
As it stands, tables are declared as static arrays of size zero. Then to access them we need to use builtins. No subscripting, no comparison, no pointer decay, etc. No passing into functions, returning from functions, etc. Nothing besides using them as arguments to wasm_table... builtins.


================
Comment at: clang/test/SemaCXX/wasm-refs-and-tables.cpp:88
+  varargs(1, table);              // expected-error {{cannot use WebAssembly table as a function parameter}}
+  table == 1;                     // expected-error {{invalid operands to binary expression ('__attribute__((address_space(1))) __externref_t[0]' and 'int')}}
+  1 >= table;                     // expected-error {{invalid operands to binary expression ('int' and '__attribute__((address_space(1))) __externref_t[0]')}}
----------------
aaron.ballman wrote:
> 
No comparisons are allowed - I have added a few tests to that effect.


================
Comment at: clang/test/SemaCXX/wasm-refs-and-tables.cpp:95
+  table ? : other_table;          // expected-error {{cannot use a WebAssembly table within a branch of a conditional expression}}
+  (void *)table;                  // expected-error {{cannot cast from a WebAssembly table}}
+  void *u;
----------------
aaron.ballman wrote:
> 
(void)table; is allowed.


================
Comment at: clang/test/SemaCXX/wasm-refs-and-tables.cpp:102
+
+  table[0];
+  table[0] = ref;
----------------
aaron.ballman wrote:
> This involves array to pointer decay, so we're forming a pointer to the table here. Why is this pointer fine but others are not?
I have disallowed this to avoid the problems you mention. Table set happens only through the builtin wasm_table_set.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139010/new/

https://reviews.llvm.org/D139010



More information about the cfe-commits mailing list