Skip to content

Commit cb87499

Browse files
authored
Fix wasm-mutate with table64 (#1535)
Consult module information for the type of `table.*` expressions to know if it's 32-bit or 64-bit.
1 parent b1ee957 commit cb87499

2 files changed

Lines changed: 22 additions & 9 deletions

File tree

crates/wasm-mutate/src/info.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub struct ModuleInfo<'a> {
4949
// function idx to type idx
5050
pub function_map: Vec<u32>,
5151
pub global_types: Vec<PrimitiveTypeInfo>,
52-
pub table_elem_types: Vec<PrimitiveTypeInfo>,
52+
pub table_types: Vec<wasmparser::TableType>,
5353
pub memory_types: Vec<wasmparser::MemoryType>,
5454

5555
// raw_sections
@@ -119,7 +119,7 @@ impl<'a> ModuleInfo<'a> {
119119
wasmparser::TypeRef::Table(ty) => {
120120
info.table_count += 1;
121121
info.imported_tables_count += 1;
122-
info.table_elem_types.push(ty.element_type.into());
122+
info.table_types.push(ty);
123123
}
124124
wasmparser::TypeRef::Tag(_ty) => {
125125
info.tag_count += 1;
@@ -143,8 +143,7 @@ impl<'a> ModuleInfo<'a> {
143143

144144
for table in reader {
145145
let table = table?;
146-
let ty = PrimitiveTypeInfo::try_from(table.ty.element_type).unwrap();
147-
info.table_elem_types.push(ty);
146+
info.table_types.push(table.ty);
148147
}
149148
}
150149
Payload::MemorySection(reader) => {

crates/wasm-mutate/src/mutators/peephole/eggsy/analysis.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub struct PeepholeMutationAnalysis {
2424
/// function idx to type idx
2525
function_map: Vec<u32>,
2626
/// table index to the type of element it has
27-
table_types: Vec<PrimitiveTypeInfo>,
27+
table_types: Vec<wasmparser::TableType>,
2828
memory_types: Vec<wasmparser::MemoryType>,
2929
}
3030

@@ -36,7 +36,7 @@ impl PeepholeMutationAnalysis {
3636
global_types: info.global_types.clone(),
3737
types_map: info.types_map.clone(),
3838
function_map: info.function_map.clone(),
39-
table_types: info.table_elem_types.clone(),
39+
table_types: info.table_types.clone(),
4040
memory_types: info.memory_types.clone(),
4141
}
4242
}
@@ -267,16 +267,30 @@ impl PeepholeMutationAnalysis {
267267
Lang::DataDrop(_) => Ok(PrimitiveTypeInfo::Empty),
268268
Lang::MemoryCopy { .. } => Ok(PrimitiveTypeInfo::Empty),
269269
Lang::MemoryFill { .. } => Ok(PrimitiveTypeInfo::Empty),
270-
Lang::TableGrow { .. } => Ok(PrimitiveTypeInfo::I32),
271-
Lang::TableSize { .. } => Ok(PrimitiveTypeInfo::I32),
270+
Lang::TableGrow(table, _) => {
271+
let ty = self.table_types[*table as usize];
272+
if ty.table64 {
273+
Ok(PrimitiveTypeInfo::I64)
274+
} else {
275+
Ok(PrimitiveTypeInfo::I32)
276+
}
277+
}
278+
Lang::TableSize(table) => {
279+
let ty = self.table_types[*table as usize];
280+
if ty.table64 {
281+
Ok(PrimitiveTypeInfo::I64)
282+
} else {
283+
Ok(PrimitiveTypeInfo::I32)
284+
}
285+
}
272286
Lang::TableInit { .. } => Ok(PrimitiveTypeInfo::Empty),
273287
Lang::ElemDrop(_) => Ok(PrimitiveTypeInfo::Empty),
274288
Lang::TableCopy { .. } => Ok(PrimitiveTypeInfo::Empty),
275289
Lang::TableFill { .. } => Ok(PrimitiveTypeInfo::Empty),
276290
Lang::TableSet(..) => Ok(PrimitiveTypeInfo::Empty),
277291
Lang::TableGet(idx, _) => {
278292
let ty = self.table_types[*idx as usize].clone();
279-
Ok(ty)
293+
Ok(ty.element_type.into())
280294
}
281295
Lang::I32UseGlobal(_) => Ok(PrimitiveTypeInfo::I32),
282296
Lang::I64UseGlobal(_) => Ok(PrimitiveTypeInfo::I64),

0 commit comments

Comments
 (0)