Skip to content

Commit 6a9c5fb

Browse files
committed
polymorphize GlobalAlloc::Function
1 parent e22b61b commit 6a9c5fb

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/librustc_codegen_llvm/common.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
257257
(value, AddressSpace::DATA)
258258
}
259259
GlobalAlloc::Function(fn_instance) => (
260-
self.get_fn_addr(fn_instance),
260+
self.get_fn_addr(fn_instance.polymorphize(self.tcx)),
261261
self.data_layout().instruction_address_space,
262262
),
263263
GlobalAlloc::Static(def_id) => {

src/librustc_mir/monomorphize/collector.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,7 @@ fn collect_miri<'tcx>(
11971197
}
11981198
}
11991199
GlobalAlloc::Function(fn_instance) => {
1200+
let fn_instance = fn_instance.polymorphize(tcx);
12001201
if should_codegen_locally(tcx, &fn_instance) {
12011202
trace!("collecting {:?} with {:#?}", alloc_id, fn_instance);
12021203
output.push(create_fn_mono_item(tcx, fn_instance, DUMMY_SP));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// run-pass
2+
fn fop<T>() {}
3+
4+
fn bar<T>() -> &'static fn() {
5+
&(fop::<T> as fn())
6+
}
7+
pub const FN: &'static fn() = &(fop::<i32> as fn());
8+
9+
fn main() {
10+
bar::<u32>();
11+
bar::<i32>();
12+
(FN)();
13+
}

0 commit comments

Comments
 (0)