@@ -133,7 +133,7 @@ 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 ( & global. init_expr , global. ty . content_type , global . ty . shared , features, types) ?;
137
137
self . module . assert_mut ( ) . globals . push ( global. ty ) ;
138
138
Ok ( ( ) )
139
139
}
@@ -162,7 +162,7 @@ impl ModuleState {
162
162
the function-references proposal"
163
163
) ;
164
164
}
165
- self . check_const_expr ( expr, table. ty . element_type . into ( ) , features, types) ?;
165
+ self . check_const_expr ( expr, table. ty . element_type . into ( ) , table . ty . shared , features, types) ?;
166
166
}
167
167
}
168
168
self . module . assert_mut ( ) . tables . push ( table. ty ) ;
@@ -182,8 +182,8 @@ impl ModuleState {
182
182
memory_index,
183
183
offset_expr,
184
184
} => {
185
- let ty = self . module . memory_at ( memory_index, offset) ?. index_type ( ) ;
186
- self . check_const_expr ( & offset_expr, ty, features, types)
185
+ let ty = self . module . memory_at ( memory_index, offset) ?;
186
+ self . check_const_expr ( & offset_expr, ty. index_type ( ) , ty . shared , features, types)
187
187
}
188
188
}
189
189
}
@@ -195,8 +195,8 @@ impl ModuleState {
195
195
types : & TypeList ,
196
196
offset : usize ,
197
197
) -> Result < ( ) > {
198
- // the `funcref` value type is allowed all the way back to the MVP, so
199
- // don't check it here
198
+ // The `funcref` value type is allowed all the way back to the MVP, so
199
+ // don't check it here.
200
200
let element_ty = match & mut e. items {
201
201
crate :: ElementItems :: Functions ( _) => RefType :: FUNC ,
202
202
crate :: ElementItems :: Expressions ( ty, _) => {
@@ -221,8 +221,7 @@ impl ModuleState {
221
221
offset,
222
222
) ) ;
223
223
}
224
-
225
- self . check_const_expr ( & offset_expr, table. index_type ( ) , features, types) ?;
224
+ self . check_const_expr ( & offset_expr, table. index_type ( ) , table. shared , features, types) ?;
226
225
}
227
226
ElementKind :: Passive | ElementKind :: Declared => {
228
227
if !features. bulk_memory ( ) {
@@ -256,8 +255,18 @@ impl ModuleState {
256
255
}
257
256
crate :: ElementItems :: Expressions ( ty, reader) => {
258
257
validate_count ( reader. count ( ) ) ?;
258
+ let shared = match ty. heap_type ( ) {
259
+ HeapType :: Abstract { shared, .. } => shared,
260
+ HeapType :: Concrete ( unpacked_index) => {
261
+ if let Some ( id) = unpacked_index. as_core_type_id ( ) {
262
+ types[ id] . composite_type . shared
263
+ } else {
264
+ todo ! ( )
265
+ }
266
+ }
267
+ } ;
259
268
for expr in reader {
260
- self . check_const_expr ( & expr?, ValType :: Ref ( ty) , features, types) ?;
269
+ self . check_const_expr ( & expr?, ValType :: Ref ( ty) , shared , features, types) ?;
261
270
}
262
271
}
263
272
}
@@ -269,6 +278,7 @@ impl ModuleState {
269
278
& mut self ,
270
279
expr : & ConstExpr < ' _ > ,
271
280
expected_ty : ValType ,
281
+ shared : bool ,
272
282
features : & WasmFeatures ,
273
283
types : & TypeList ,
274
284
) -> Result < ( ) > {
@@ -286,6 +296,7 @@ impl ModuleState {
286
296
module : & mut self . module ,
287
297
} ,
288
298
features,
299
+ shared,
289
300
} ;
290
301
291
302
let mut ops = expr. get_operators_reader ( ) ;
@@ -309,6 +320,7 @@ impl ModuleState {
309
320
resources : OperatorValidatorResources < ' a > ,
310
321
order : Order ,
311
322
features : & ' a WasmFeatures ,
323
+ shared : bool ,
312
324
}
313
325
314
326
impl VisitConstOperator < ' _ > {
@@ -374,6 +386,12 @@ impl ModuleState {
374
386
self . offset ,
375
387
) ) ;
376
388
}
389
+ if self . shared && !global. shared {
390
+ return Err ( BinaryReaderError :: new (
391
+ "invalid type: constant expression must be shared" ,
392
+ self . offset ,
393
+ ) ) ;
394
+ }
377
395
Ok ( ( ) )
378
396
}
379
397
0 commit comments