Remove redundant validation for function locals.

Remove the MAX_LOCALS constraint, and the local type validation.
These are checked by whatever is performing proper validation.
This commit is contained in:
Dan Gohman
2017-11-13 14:34:35 -08:00
parent 648c1b33ba
commit 355e3e3c15

View File

@@ -14,10 +14,6 @@ use state::TranslationState;
use translation_utils::Local; use translation_utils::Local;
use wasmparser::{self, BinaryReader}; use wasmparser::{self, BinaryReader};
/// Maximum number of local variables permitted in a function. The translation fails with a
/// `CtonError::ImplLimitExceeded` error if the limit is exceeded.
const MAX_LOCALS: usize = 50_000;
/// WebAssembly to Cretonne IL function translator. /// WebAssembly to Cretonne IL function translator.
/// ///
/// A `FuncTranslator` is used to translate a binary WebAssembly function into Cretonne IL guided /// A `FuncTranslator` is used to translate a binary WebAssembly function into Cretonne IL guided
@@ -145,7 +141,7 @@ fn parse_local_decls(
let (count, ty) = reader.read_local_decl(&mut locals_total).map_err(|_| { let (count, ty) = reader.read_local_decl(&mut locals_total).map_err(|_| {
CtonError::InvalidInput CtonError::InvalidInput
})?; })?;
declare_locals(builder, count, ty, &mut next_local)?; declare_locals(builder, count, ty, &mut next_local);
} }
Ok(()) Ok(())
@@ -159,7 +155,7 @@ fn declare_locals(
count: u32, count: u32,
wasm_type: wasmparser::Type, wasm_type: wasmparser::Type,
next_local: &mut usize, next_local: &mut usize,
) -> CtonResult { ) {
// All locals are initialized to 0. // All locals are initialized to 0.
use wasmparser::Type::*; use wasmparser::Type::*;
let zeroval = match wasm_type { let zeroval = match wasm_type {
@@ -167,24 +163,16 @@ fn declare_locals(
I64 => builder.ins().iconst(ir::types::I64, 0), I64 => builder.ins().iconst(ir::types::I64, 0),
F32 => builder.ins().f32const(ir::immediates::Ieee32::with_bits(0)), F32 => builder.ins().f32const(ir::immediates::Ieee32::with_bits(0)),
F64 => builder.ins().f64const(ir::immediates::Ieee64::with_bits(0)), F64 => builder.ins().f64const(ir::immediates::Ieee64::with_bits(0)),
_ => return Err(CtonError::InvalidInput), _ => panic!("invalid local type"),
}; };
let ty = builder.func.dfg.value_type(zeroval); let ty = builder.func.dfg.value_type(zeroval);
for _ in 0..count { for _ in 0..count {
// This implementation limit is arbitrary, but it ensures that a small function can't blow
// up the compiler by declaring millions of locals.
if *next_local >= MAX_LOCALS {
return Err(CtonError::ImplLimitExceeded);
}
let local = Local::new(*next_local); let local = Local::new(*next_local);
builder.declare_var(local, ty); builder.declare_var(local, ty);
builder.def_var(local, zeroval); builder.def_var(local, zeroval);
*next_local += 1; *next_local += 1;
} }
Ok(())
} }
/// Parse the function body in `reader`. /// Parse the function body in `reader`.