You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Wasm][Clang] Add support for pointer to externref
Add support for values of type `__externref_t *`.
We add a special table called `__externref_table`. Loads and stores
to externref pointers are converted to table_get and table_set
instructions using `__externref_table`.
This is a bit tricky because tables are given type array of externref
`__externref_t table[]`. Tables are also not first class values and
most operations don't work on them. However, arrays decay to pointers.
Previously since `__externref_t*` was always illegal, this wasn't a
problem. I dealt with this by preventing arrays from decaying to
pointers if the value type of the array is `__externref_t`.
&ref; // expected-error {{cannot take address of WebAssembly reference}}
63
63
intfoo=40;
64
-
(__externref_t*)(&foo); // expected-error {{pointer to WebAssembly reference type is not allowed}}
65
-
(__externref_t****)(&foo); // expected-error {{pointer to WebAssembly reference type is not allowed}}
64
+
(__externref_t****)(&foo);
66
65
sizeof(ref); // expected-error {{invalid application of 'sizeof' to sizeless type '__externref_t'}}
67
66
sizeof(__externref_t); // expected-error {{invalid application of 'sizeof' to sizeless type '__externref_t'}}
68
67
sizeof(__externref_t[0]); // expected-error {{invalid application of 'sizeof' to WebAssembly table}}
69
68
sizeof(table); // expected-error {{invalid application of 'sizeof' to WebAssembly table}}
70
69
sizeof(__externref_t[0][0]); // expected-error {{multi-dimensional arrays of WebAssembly references are not allowed}}
71
-
sizeof(__externref_t*);// expected-error {{pointer to WebAssembly reference type is not allowed}}
72
-
sizeof(__externref_t***);// expected-error {{pointer to WebAssembly reference type is not allowed}};
70
+
sizeof(__externref_t*);
71
+
sizeof(__externref_t***);
73
72
// expected-warning@+1 {{'_Alignof' applied to an expression is a GNU extension}}
74
73
_Alignof(ref); // expected-error {{invalid application of 'alignof' to sizeless type '__externref_t'}}
75
74
_Alignof(__externref_t); // expected-error {{invalid application of 'alignof' to sizeless type '__externref_t'}}
76
75
_Alignof(__externref_t[]); // expected-error {{invalid application of 'alignof' to sizeless type '__externref_t'}}
77
76
_Alignof(__externref_t[0]); // expected-error {{invalid application of 'alignof' to sizeless type '__externref_t'}}
78
77
_Alignof(table); // expected-warning {{'_Alignof' applied to an expression is a GNU extension}} expected-error {{invalid application of 'alignof' to WebAssembly table}}
79
78
_Alignof(__externref_t[0][0]); // expected-error {{multi-dimensional arrays of WebAssembly references are not allowed}}
80
-
_Alignof(__externref_t*);// expected-error {{pointer to WebAssembly reference type is not allowed}}
81
-
_Alignof(__externref_t***);// expected-error {{pointer to WebAssembly reference type is not allowed}};
79
+
_Alignof(__externref_t*);
80
+
_Alignof(__externref_t***);
82
81
varargs(1, ref); // expected-error {{cannot pass expression of type '__externref_t' to variadic function}}
83
82
84
83
__externref_tlt1[0]; // expected-error {{WebAssembly table cannot be declared within a function}}
85
84
static__externref_tlt2[0]; // expected-error {{WebAssembly table cannot be declared within a function}}
86
85
static__externref_tlt3[0][0]; // expected-error {{multi-dimensional arrays of WebAssembly references are not allowed}}
87
86
static__externref_t(*lt4)[0]; // expected-error {{cannot form a pointer to a WebAssembly table}}
88
87
// conly-error@+2 {{cannot use WebAssembly table as a function parameter}}
89
-
// cpp-error@+1 {{no matching function for call to 'illegal_argument_1'}}
90
-
illegal_argument_1(table);
88
+
// cpp-error@+1 {{no matching function for call to 'okay_argument_3'}}
89
+
okay_argument_3(table);
91
90
varargs(1, table); // expected-error {{cannot use WebAssembly table as a function parameter}}
92
-
table==1; // expected-error {{invalid operands to binary expression ('__attribute__((address_space(1))) __externref_t[0]' and 'int')}}
93
-
1 >= table; // expected-error {{invalid operands to binary expression ('int' and '__attribute__((address_space(1))) __externref_t[0]')}}
94
-
table==other_table; // expected-error {{invalid operands to binary expression ('__attribute__((address_space(1))) __externref_t[0]' and '__attribute__((address_space(1))) __externref_t[0]')}}
95
-
table!=-table; // expected-error {{invalid argument type '__attribute__((address_space(1))) __externref_t *' to unary expression}}
96
-
!table; // expected-error {{invalid argument type '__attribute__((address_space(1))) __externref_t *' to unary expression}}
91
+
table==1; // expected-error {{cannot cast from a WebAssembly table}}
92
+
1 >= table; // expected-error {{cannot cast from a WebAssembly table}}
93
+
table==other_table; // expected-error {{cannot cast from a WebAssembly table}}
94
+
table!=-table; // expected-error {{cannot cast from a WebAssembly table}}
95
+
!table; // expected-error {{cannot cast from a WebAssembly table}}
97
96
1&&table; // expected-error {{invalid operands to binary expression ('int' and '__attribute__((address_space(1))) __externref_t[0]')}}
98
97
table||1; // expected-error {{invalid operands to binary expression ('__attribute__((address_space(1))) __externref_t[0]' and 'int')}}
99
-
1 ? table : table; // expected-error {{cannot use a WebAssembly table within a branch of a conditional expression}}
100
-
table ? : other_table; // expected-error {{cannot use a WebAssembly table within a branch of a conditional expression}}
98
+
table ? : other_table; // expected-error {{cannot cast from a WebAssembly table}}
101
99
(void*)table; // expected-error {{cannot cast from a WebAssembly table}}
102
100
void*u;
103
101
u=table; // expected-error {{cannot assign a WebAssembly table}}
104
102
void*v=table; // expected-error {{cannot assign a WebAssembly table}}
105
103
&table; // expected-error {{cannot form a reference to a WebAssembly table}}
106
-
(void)table;
104
+
(void)table;// conly-error {{cannot cast from a WebAssembly table}}
107
105
108
106
table[0]; // expected-error {{cannot subscript a WebAssembly table}}
109
107
table[0] =ref; // expected-error {{cannot subscript a WebAssembly table}}
0 commit comments