1
Fork 0

polymorphize GlobalAlloc::Function

This commit is contained in:
Bastian Kauschke 2020-07-22 12:50:26 +02:00
parent e22b61bff0
commit 6a9c5fb4cc
3 changed files with 15 additions and 1 deletions

View file

@ -257,7 +257,7 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
(value, AddressSpace::DATA) (value, AddressSpace::DATA)
} }
GlobalAlloc::Function(fn_instance) => ( GlobalAlloc::Function(fn_instance) => (
self.get_fn_addr(fn_instance), self.get_fn_addr(fn_instance.polymorphize(self.tcx)),
self.data_layout().instruction_address_space, self.data_layout().instruction_address_space,
), ),
GlobalAlloc::Static(def_id) => { GlobalAlloc::Static(def_id) => {

View file

@ -1197,6 +1197,7 @@ fn collect_miri<'tcx>(
} }
} }
GlobalAlloc::Function(fn_instance) => { GlobalAlloc::Function(fn_instance) => {
let fn_instance = fn_instance.polymorphize(tcx);
if should_codegen_locally(tcx, &fn_instance) { if should_codegen_locally(tcx, &fn_instance) {
trace!("collecting {:?} with {:#?}", alloc_id, fn_instance); trace!("collecting {:?} with {:#?}", alloc_id, fn_instance);
output.push(create_fn_mono_item(tcx, fn_instance, DUMMY_SP)); output.push(create_fn_mono_item(tcx, fn_instance, DUMMY_SP));

View file

@ -0,0 +1,13 @@
// run-pass
fn fop<T>() {}
fn bar<T>() -> &'static fn() {
&(fop::<T> as fn())
}
pub const FN: &'static fn() = &(fop::<i32> as fn());
fn main() {
bar::<u32>();
bar::<i32>();
(FN)();
}