@@ -133,7 +133,13 @@ impl ModuleState {
133
133
) -> Result < ( ) > {
134
134
self . module
135
135
. check_global_type ( & mut global. ty , features, types, offset) ?;
136
- self . check_const_expr ( & global. init_expr , global. ty . content_type , features, types) ?;
136
+ self . check_const_expr (
137
+ & global. init_expr ,
138
+ global. ty . content_type ,
139
+ global. ty . shared ,
140
+ features,
141
+ types,
142
+ ) ?;
137
143
self . module . assert_mut ( ) . globals . push ( global. ty ) ;
138
144
Ok ( ( ) )
139
145
}
@@ -162,7 +168,13 @@ impl ModuleState {
162
168
the function-references proposal"
163
169
) ;
164
170
}
165
- self . check_const_expr ( expr, table. ty . element_type . into ( ) , features, types) ?;
171
+ self . check_const_expr (
172
+ expr,
173
+ table. ty . element_type . into ( ) ,
174
+ table. ty . shared ,
175
+ features,
176
+ types,
177
+ ) ?;
166
178
}
167
179
}
168
180
self . module . assert_mut ( ) . tables . push ( table. ty ) ;
@@ -182,8 +194,8 @@ impl ModuleState {
182
194
memory_index,
183
195
offset_expr,
184
196
} => {
185
- let ty = self . module . memory_at ( memory_index, offset) ?. index_type ( ) ;
186
- self . check_const_expr ( & offset_expr, ty, features, types)
197
+ let ty = self . module . memory_at ( memory_index, offset) ?;
198
+ self . check_const_expr ( & offset_expr, ty. index_type ( ) , ty . shared , features, types)
187
199
}
188
200
}
189
201
}
@@ -195,8 +207,8 @@ impl ModuleState {
195
207
types : & TypeList ,
196
208
offset : usize ,
197
209
) -> Result < ( ) > {
198
- // the `funcref` value type is allowed all the way back to the MVP, so
199
- // don't check it here
210
+ // The `funcref` value type is allowed all the way back to the MVP, so
211
+ // don't check it here.
200
212
let element_ty = match & mut e. items {
201
213
crate :: ElementItems :: Functions ( _) => RefType :: FUNC ,
202
214
crate :: ElementItems :: Expressions ( ty, _) => {
@@ -221,8 +233,13 @@ impl ModuleState {
221
233
offset,
222
234
) ) ;
223
235
}
224
-
225
- self . check_const_expr ( & offset_expr, table. index_type ( ) , features, types) ?;
236
+ self . check_const_expr (
237
+ & offset_expr,
238
+ table. index_type ( ) ,
239
+ table. shared ,
240
+ features,
241
+ types,
242
+ ) ?;
226
243
}
227
244
ElementKind :: Passive | ElementKind :: Declared => {
228
245
if !features. bulk_memory ( ) {
@@ -256,8 +273,18 @@ impl ModuleState {
256
273
}
257
274
crate :: ElementItems :: Expressions ( ty, reader) => {
258
275
validate_count ( reader. count ( ) ) ?;
276
+ let shared = match ty. heap_type ( ) {
277
+ HeapType :: Abstract { shared, .. } => shared,
278
+ HeapType :: Concrete ( unpacked_index) => {
279
+ if let Some ( id) = unpacked_index. as_core_type_id ( ) {
280
+ types[ id] . composite_type . shared
281
+ } else {
282
+ todo ! ( )
283
+ }
284
+ }
285
+ } ;
259
286
for expr in reader {
260
- self . check_const_expr ( & expr?, ValType :: Ref ( ty) , features, types) ?;
287
+ self . check_const_expr ( & expr?, ValType :: Ref ( ty) , shared , features, types) ?;
261
288
}
262
289
}
263
290
}
@@ -269,6 +296,7 @@ impl ModuleState {
269
296
& mut self ,
270
297
expr : & ConstExpr < ' _ > ,
271
298
expected_ty : ValType ,
299
+ shared : bool ,
272
300
features : & WasmFeatures ,
273
301
types : & TypeList ,
274
302
) -> Result < ( ) > {
@@ -286,6 +314,7 @@ impl ModuleState {
286
314
module : & mut self . module ,
287
315
} ,
288
316
features,
317
+ shared,
289
318
} ;
290
319
291
320
let mut ops = expr. get_operators_reader ( ) ;
@@ -309,6 +338,7 @@ impl ModuleState {
309
338
resources : OperatorValidatorResources < ' a > ,
310
339
order : Order ,
311
340
features : & ' a WasmFeatures ,
341
+ shared : bool ,
312
342
}
313
343
314
344
impl VisitConstOperator < ' _ > {
@@ -374,6 +404,12 @@ impl ModuleState {
374
404
self . offset ,
375
405
) ) ;
376
406
}
407
+ if self . shared && !global. shared {
408
+ return Err ( BinaryReaderError :: new (
409
+ "invalid type: constant expression must be shared" ,
410
+ self . offset ,
411
+ ) ) ;
412
+ }
377
413
Ok ( ( ) )
378
414
}
379
415
0 commit comments