diff --git a/cranelift/src/wasm.rs b/cranelift/src/wasm.rs index c54cfa85d0..c418c3cc2c 100644 --- a/cranelift/src/wasm.rs +++ b/cranelift/src/wasm.rs @@ -195,6 +195,7 @@ fn handle_module( CtonError::Verifier(err) => { return Err(pretty_verifier_error(&context.func, None, err)); } + CtonError::InvalidInput | CtonError::ImplLimitExceeded | CtonError::CodeTooLarge => return Err(String::from(error.description())), } @@ -207,6 +208,7 @@ fn handle_module( CtonError::Verifier(err) => { return Err(pretty_verifier_error(&context.func, None, err)); } + CtonError::InvalidInput | CtonError::ImplLimitExceeded | CtonError::CodeTooLarge => return Err(String::from(error.description())), } diff --git a/lib/cretonne/src/result.rs b/lib/cretonne/src/result.rs index f4d7316fb5..b5e9861f95 100644 --- a/lib/cretonne/src/result.rs +++ b/lib/cretonne/src/result.rs @@ -9,6 +9,12 @@ use std::fmt; /// When Cretonne fails to compile a function, it will return one of these error codes. #[derive(Debug, PartialEq, Eq)] pub enum CtonError { + /// The input is invalid. + /// + /// This error code is used by a WebAssembly translator when it encounters invalid WebAssembly + /// code. This should never happen for validated WebAssembly code. + InvalidInput, + /// An IL verifier error. /// /// This always represents a bug, either in the code that generated IL for Cretonne, or a bug @@ -37,6 +43,7 @@ impl fmt::Display for CtonError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { CtonError::Verifier(ref e) => write!(f, "Verifier error: {}", e), + CtonError::InvalidInput | CtonError::ImplLimitExceeded | CtonError::CodeTooLarge => f.write_str(self.description()), } @@ -46,6 +53,7 @@ impl fmt::Display for CtonError { impl StdError for CtonError { fn description(&self) -> &str { match *self { + CtonError::InvalidInput => "Invalid input code", CtonError::Verifier(ref e) => &e.message, CtonError::ImplLimitExceeded => "Implementation limit exceeded", CtonError::CodeTooLarge => "Code for function is too large", @@ -54,6 +62,7 @@ impl StdError for CtonError { fn cause(&self) -> Option<&StdError> { match *self { CtonError::Verifier(ref e) => Some(e), + CtonError::InvalidInput | CtonError::ImplLimitExceeded | CtonError::CodeTooLarge => None, }