(&mut self, func: &Function)
| 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)] |
no test coverage detected