From 9a9054ad236a47c082e289ead24dec801084a66f Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 18 Jul 2018 13:43:17 +0200 Subject: [PATCH] Disable define_function to prevent crashing on things cranelift doesn't yet support --- example.rs | 5 +++-- src/base.rs | 4 +++- src/lib.rs | 38 ++++++++++++++++++++------------------ 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/example.rs b/example.rs index 94215a50fc1b..7dc816aa7dc9 100644 --- a/example.rs +++ b/example.rs @@ -1,5 +1,6 @@ #![feature(no_core, lang_items)] #![no_core] +#![allow(dead_code)] #[lang="sized"] trait Sized {} @@ -52,14 +53,14 @@ fn bcd(b: bool, a: u8) -> u8 { } // FIXME make calls work -/*fn call() { +fn call() { abc(42); } fn indirect_call() { let f: fn() = call; f(); -}*/ +} enum BoolOption { Some(bool), diff --git a/src/base.rs b/src/base.rs index 6f72fadf4872..31eb6e462bfd 100644 --- a/src/base.rs +++ b/src/base.rs @@ -50,7 +50,9 @@ pub fn trans_mono_item<'a, 'tcx: 'a>(cx: &mut CodegenCx<'a, 'tcx, CurrentBackend } context.func = f; - cx.module.define_function(func_id, context).unwrap(); + // TODO: cranelift doesn't yet support some of the things needed + // cx.module.define_function(func_id, context).unwrap(); + context.clear(); } inst => cx.tcx.sess.warn(&format!("Unimplemented instance {:?}", inst)), diff --git a/src/lib.rs b/src/lib.rs index dc640838b6b8..e02c431b21b6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -192,27 +192,29 @@ impl CodegenBackend for CraneliftCodegenBackend { tcx.sess.warn("Compiled everything"); - module.finalize_all(); + // TODO: this doesn't work most of the time + if false { + module.finalize_all(); + tcx.sess.warn("Finalized everything"); - tcx.sess.warn("Finalized everything"); - - for (inst, func_id) in def_id_fn_id_map.iter() { - //if tcx.absolute_item_path_str(inst.def_id()) != "example::ret_42" { - if tcx.absolute_item_path_str(inst.def_id()) != "example::option_unwrap_or" { - continue; + for (inst, func_id) in def_id_fn_id_map.iter() { + //if tcx.absolute_item_path_str(inst.def_id()) != "example::ret_42" { + if tcx.absolute_item_path_str(inst.def_id()) != "example::option_unwrap_or" { + continue; + } + let finalized_function: *const u8 = module.finalize_function(*func_id); + /*let f: extern "C" fn(&mut u32) = unsafe { ::std::mem::transmute(finalized_function) }; + let mut res = 0u32; + f(&mut res); + tcx.sess.warn(&format!("ret_42 returned {}", res));*/ + let f: extern "C" fn(&mut bool, &u8, bool) = unsafe { ::std::mem::transmute(finalized_function) }; + let mut res = false; + f(&mut res, &3, false); + tcx.sess.warn(&format!("option_unwrap_or returned {}", res)); } - let finalized_function: *const u8 = module.finalize_function(*func_id); - /*let f: extern "C" fn(&mut u32) = unsafe { ::std::mem::transmute(finalized_function) }; - let mut res = 0u32; - f(&mut res); - tcx.sess.warn(&format!("ret_42 returned {}", res));*/ - let f: extern "C" fn(&mut bool, &u8, bool) = unsafe { ::std::mem::transmute(finalized_function) }; - let mut res = false; - f(&mut res, &3, false); - tcx.sess.warn(&format!("option_unwrap_or returned {}", res)); - } - module.finish(); + module.finish(); + } tcx.sess.fatal("unimplemented");