diff options
| author | Bastian Kauschke <bastian_kauschke@hotmail.de> | 2020-07-22 12:50:26 +0200 |
|---|---|---|
| committer | Bastian Kauschke <bastian_kauschke@hotmail.de> | 2020-07-22 17:02:58 +0200 |
| commit | 6a9c5fb4cc499bc828422e32689c8f098542f821 (patch) | |
| tree | 867936b0cdc53888974da8b4bda8284c15fdfa09 | |
| parent | e22b61bff0bdd08be7665607cb7be3748c8a35d2 (diff) | |
| download | rust-6a9c5fb4cc499bc828422e32689c8f098542f821.tar.gz rust-6a9c5fb4cc499bc828422e32689c8f098542f821.zip | |
polymorphize GlobalAlloc::Function
| -rw-r--r-- | src/librustc_codegen_llvm/common.rs | 2 | ||||
| -rw-r--r-- | src/librustc_mir/monomorphize/collector.rs | 1 | ||||
| -rw-r--r-- | src/test/ui/polymorphization/promoted-function.rs | 13 |
3 files changed, 15 insertions, 1 deletions
diff --git a/src/librustc_codegen_llvm/common.rs b/src/librustc_codegen_llvm/common.rs index 0e1cd8e493d..2a50d4a46d2 100644 --- a/src/librustc_codegen_llvm/common.rs +++ b/src/librustc_codegen_llvm/common.rs @@ -257,7 +257,7 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> { (value, AddressSpace::DATA) } 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, ), GlobalAlloc::Static(def_id) => { diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index 0b5f27fc17a..30d25270f03 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -1197,6 +1197,7 @@ fn collect_miri<'tcx>( } } GlobalAlloc::Function(fn_instance) => { + let fn_instance = fn_instance.polymorphize(tcx); if should_codegen_locally(tcx, &fn_instance) { trace!("collecting {:?} with {:#?}", alloc_id, fn_instance); output.push(create_fn_mono_item(tcx, fn_instance, DUMMY_SP)); diff --git a/src/test/ui/polymorphization/promoted-function.rs b/src/test/ui/polymorphization/promoted-function.rs new file mode 100644 index 00000000000..0d3af7a89c2 --- /dev/null +++ b/src/test/ui/polymorphization/promoted-function.rs @@ -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)(); +} |
