diff --git a/examples/mini_core.rs b/examples/mini_core.rs index b6f5ad75890..0c9eb7a01f0 100644 --- a/examples/mini_core.rs +++ b/examples/mini_core.rs @@ -170,6 +170,13 @@ impl PartialEq for *const T { } } +pub enum Option { + Some(T), + None, +} + +pub use Option::*; + #[lang = "phantom_data"] pub struct PhantomData; diff --git a/examples/mini_core_hello_world.rs b/examples/mini_core_hello_world.rs index 1aa3a1fc2dd..a60d2363ad1 100644 --- a/examples/mini_core_hello_world.rs +++ b/examples/mini_core_hello_world.rs @@ -151,4 +151,10 @@ fn main() { text: "Outer got dropped!\0", inner: NoisyDropInner, }; + + const FUNC_REF: Option = Some(main); + match FUNC_REF { + Some(_) => {}, + None => assert!(false), + } } diff --git a/src/constant.rs b/src/constant.rs index 9bb89b88b21..9274d313259 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -224,18 +224,6 @@ fn define_all_allocs<'a, 'tcx: 'a, B: Backend + 'a>( data_ctx.define(alloc.bytes.to_vec().into_boxed_slice()); for &(offset, reloc) in alloc.relocations.iter() { - let data_id = match tcx.alloc_map.lock().get(reloc).unwrap() { - AllocType::Memory(_) => { - cx.todo.insert(TodoItem::Alloc(reloc)); - data_id_for_alloc_id(module, reloc) - } - AllocType::Function(_) => unimplemented!("function static reference"), - AllocType::Static(def_id) => { - cx.todo.insert(TodoItem::Static(def_id)); - data_id_for_static(tcx, module, def_id) - } - }; - let reloc_offset = { let endianness = tcx.data_layout.endian; let offset = offset.bytes() as usize; @@ -244,6 +232,24 @@ fn define_all_allocs<'a, 'tcx: 'a, B: Backend + 'a>( read_target_uint(endianness, bytes).unwrap() }; + let data_id = match tcx.alloc_map.lock().get(reloc).unwrap() { + AllocType::Function(instance) => { + let (func_name, sig) = crate::abi::get_function_name_and_sig(tcx, instance); + let func_id = module.declare_function(&func_name, Linkage::Import, &sig).unwrap(); + let local_func_id = module.declare_func_in_data(func_id, &mut data_ctx); + data_ctx.write_function_addr(reloc_offset as u32, local_func_id); + continue; + }, + AllocType::Memory(_) => { + cx.todo.insert(TodoItem::Alloc(reloc)); + data_id_for_alloc_id(module, reloc) + } + AllocType::Static(def_id) => { + cx.todo.insert(TodoItem::Static(def_id)); + data_id_for_static(tcx, module, def_id) + } + }; + let global_value = module.declare_data_in_data(data_id, &mut data_ctx); data_ctx.write_data_addr(reloc_offset as u32, global_value, 0); }