better asserts and errors in various places

This commit is contained in:
Chris Fallin 2024-05-11 21:42:27 -07:00 committed by Graham Kelly
parent 63616b502a
commit 0b72e1df5a
2 changed files with 42 additions and 17 deletions

View file

@ -153,21 +153,21 @@ impl<'a> WasmFuncBackend<'a> {
}
}
}
WasmBlock::BlockParams { from, to } => {
debug_assert_eq!(from.len(), to.len());
for (&from, &(_, to)) in from.iter().zip(to.iter()) {
if self.locals.values[to].is_empty() {
continue;
}
self.lower_value(from, func);
}
for &(_, to) in to.iter().rev() {
if self.locals.values[to].is_empty() {
continue;
}
self.lower_set_value(to, func);
}
}
// WasmBlock::BlockParams { from, to } => {
// debug_assert_eq!(from.len(), to.len());
// for (&from, &(_, to)) in from.iter().zip(to.iter()) {
// if self.locals.values[to].is_empty() {
// continue;
// }
// self.lower_value(from, func);
// }
// for &(_, to) in to.iter().rev() {
// if self.locals.values[to].is_empty() {
// continue;
// }
// self.lower_set_value(to, func);
// }
// }
WasmBlock::Return { values } => {
for &value in &values[..] {
self.lower_value(value, func);
@ -180,6 +180,31 @@ impl<'a> WasmFuncBackend<'a> {
}
func.instruction(&wasm_encoder::Instruction::ReturnCall(f.index() as u32));
}
WasmBlock::BlockParams { from, to } => {
debug_assert_eq!(from.len(), to.len());
for (&from, &(to_ty, to)) in from.iter().zip(to.iter()) {
if self.locals.values[to].is_empty() {
continue;
}
let from_ty = self.body.values[self.body.resolve_alias(from)]
.ty(&self.body.type_pool)
.unwrap();
assert_eq!(from_ty, to_ty);
if self.locals.values[from].len() == 1 {
assert_eq!(from_ty, self.locals.locals[self.locals.values[from][0]]);
}
self.lower_value(from, func);
}
for &(to_ty, to) in to.iter().rev() {
if self.locals.values[to].is_empty() {
continue;
}
if self.locals.values[to].len() == 1 {
assert_eq!(to_ty, self.locals.locals[self.locals.values[to][0]]);
}
self.lower_set_value(to, func);
}
}
WasmBlock::ReturnCallIndirect { sig, table, values } => {
for &value in &values[..] {
self.lower_value(value, func);

View file

@ -423,8 +423,8 @@ impl FunctionBody {
let u = self.resolve_alias(u);
if block_inst[u].is_none() {
bad.push(format!(
"Use of arg {} at {:?} illegal: not defined",
u, inst
"Use of arg {} at {:?} in {} illegal: not defined",
u, inst, block
));
return;
}