MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / check_for_crash

Method check_for_crash

cranelift/src/bugpoint.rs:946–997  ·  view source on GitHub ↗
(&mut self, func: &Function)

Source from the content-addressed store, hash-verified

944 }
945
946 fn check_for_crash(&mut self, func: &Function) -> CheckResult {
947 self.context.clear();
948
949 self.context.func = func.clone();
950
951 use std::io::Write;
952 std::io::stdout().flush().unwrap(); // Flush stdout to sync with panic messages on stderr
953
954 match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
955 cranelift_codegen::verifier::verify_function(&func, self.isa).err()
956 })) {
957 Ok(Some(_)) => return CheckResult::Succeed,
958 Ok(None) => {}
959 // The verifier panicked. Compiling it will probably give the same panic.
960 // We treat it as succeeding to make it possible to reduce for the actual error.
961 // FIXME prevent verifier panic on removing block0.
962 Err(_) => return CheckResult::Succeed,
963 }
964
965 #[cfg(test)]
966 if true {
967 // For testing purposes we emulate a panic caused by the existence of
968 // a `call` instruction.
969 let contains_call = func.layout.blocks().any(|block| {
970 func.layout
971 .block_insts(block)
972 .any(|inst| match func.dfg.insts[inst] {
973 InstructionData::Call { .. } => true,
974 _ => false,
975 })
976 });
977 if contains_call {
978 return CheckResult::Crash("test crash".to_string());
979 } else {
980 return CheckResult::Succeed;
981 }
982 }
983
984 let old_panic_hook = std::panic::take_hook();
985 std::panic::set_hook(Box::new(|_| {})); // silence panics
986
987 let res = match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
988 let _ = self.context.compile(self.isa, &mut Default::default());
989 })) {
990 Ok(()) => CheckResult::Succeed,
991 Err(err) => CheckResult::Crash(get_panic_string(err)),
992 };
993
994 std::panic::set_hook(old_panic_hook);
995
996 res
997 }
998}
999
1000#[cfg(test)]

Callers 3

try_resolve_aliasesFunction · 0.80
try_remove_srclocsFunction · 0.80
reduceFunction · 0.80

Calls 14

verify_functionFunction · 0.85
get_panic_stringFunction · 0.85
anyMethod · 0.80
blocksMethod · 0.80
block_instsMethod · 0.80
stdoutFunction · 0.50
newFunction · 0.50
clearMethod · 0.45
cloneMethod · 0.45
unwrapMethod · 0.45
flushMethod · 0.45
errMethod · 0.45

Tested by

no test coverage detected