Implement function reference in static
This commit is contained in:
parent
d5bfb76216
commit
7168563649
3 changed files with 31 additions and 12 deletions
|
@ -170,6 +170,13 @@ impl<T: ?Sized> PartialEq for *const T {
|
|||
}
|
||||
}
|
||||
|
||||
pub enum Option<T> {
|
||||
Some(T),
|
||||
None,
|
||||
}
|
||||
|
||||
pub use Option::*;
|
||||
|
||||
#[lang = "phantom_data"]
|
||||
pub struct PhantomData<T: ?Sized>;
|
||||
|
||||
|
|
|
@ -151,4 +151,10 @@ fn main() {
|
|||
text: "Outer got dropped!\0",
|
||||
inner: NoisyDropInner,
|
||||
};
|
||||
|
||||
const FUNC_REF: Option<fn()> = Some(main);
|
||||
match FUNC_REF {
|
||||
Some(_) => {},
|
||||
None => assert!(false),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue