2021-11-14 02:00:34 -06:00
|
|
|
#![no_main]
|
|
|
|
use libfuzzer_sys::fuzz_target;
|
|
|
|
|
2024-05-09 15:30:38 -05:00
|
|
|
use waffle::{FrontendError, FrontendOptions, Module, OptOptions};
|
2021-11-14 02:00:34 -06:00
|
|
|
|
|
|
|
fuzz_target!(|module: wasm_smith::Module| {
|
|
|
|
let _ = env_logger::try_init();
|
2021-11-20 14:20:34 -06:00
|
|
|
log::debug!("original module: {:?}", module);
|
2021-11-14 02:00:34 -06:00
|
|
|
let orig_bytes = module.to_bytes();
|
2023-02-16 18:20:54 -06:00
|
|
|
let mut parsed_module =
|
|
|
|
match Module::from_wasm_bytes(&orig_bytes[..], &FrontendOptions::default()) {
|
|
|
|
Ok(m) => m,
|
|
|
|
Err(e) => {
|
|
|
|
match e.downcast::<FrontendError>() {
|
|
|
|
Ok(FrontendError::UnsupportedFeature(_)) | Ok(FrontendError::TooLarge(_)) => {
|
|
|
|
// Just skip this case.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Ok(e) => {
|
|
|
|
panic!("Frontend error: {:?}", e);
|
|
|
|
}
|
|
|
|
Err(e) => {
|
|
|
|
panic!("Other error when parsing module: {:?}", e);
|
|
|
|
}
|
2022-11-29 12:05:43 -06:00
|
|
|
}
|
|
|
|
}
|
2023-02-16 18:20:54 -06:00
|
|
|
};
|
2023-02-07 16:34:59 -06:00
|
|
|
parsed_module.expand_all_funcs().unwrap();
|
2024-05-09 15:30:38 -05:00
|
|
|
parsed_module.per_func_body(|body| body.optimize(&OptOptions::default()));
|
2021-11-14 02:00:34 -06:00
|
|
|
let _ = parsed_module.to_wasm_bytes();
|
|
|
|
});
|