1
Fork 0

Make declare_fn accept PolyFnSig instead of Ty.

This commit is contained in:
Masaki Hara 2018-10-06 22:58:36 +09:00
parent 2075316064
commit 06b6b1c790
5 changed files with 17 additions and 19 deletions

View file

@ -91,7 +91,7 @@ pub fn get_fn(
llfn llfn
} }
} else { } else {
let llfn = declare::declare_fn(cx, &sym, fn_ty, instance.is_vtable_shim()); let llfn = declare::declare_fn(cx, &sym, common::ty_fn_sig_vtable(cx, fn_ty, instance.is_vtable_shim()));
assert_eq!(common::val_ty(llfn), llptrty); assert_eq!(common::val_ty(llfn), llptrty);
debug!("get_fn: not casting pointer!"); debug!("get_fn: not casting pointer!");

View file

@ -404,15 +404,15 @@ impl<'b, 'tcx> CodegenCx<'b, 'tcx> {
return llfn; return llfn;
} }
let ty = tcx.mk_fn_ptr(ty::Binder::bind(tcx.mk_fn_sig( let sig = ty::Binder::bind(tcx.mk_fn_sig(
iter::once(tcx.mk_mut_ptr(tcx.types.u8)), iter::once(tcx.mk_mut_ptr(tcx.types.u8)),
tcx.types.never, tcx.types.never,
false, false,
hir::Unsafety::Unsafe, hir::Unsafety::Unsafe,
Abi::C Abi::C
))); ));
let llfn = declare::declare_fn(self, "rust_eh_unwind_resume", ty, false); let llfn = declare::declare_fn(self, "rust_eh_unwind_resume", sig);
attributes::unwind(llfn, true); attributes::unwind(llfn, true);
attributes::apply_target_cpu_attr(self, llfn); attributes::apply_target_cpu_attr(self, llfn);
unwresume.set(Some(llfn)); unwresume.set(Some(llfn));

View file

@ -22,7 +22,7 @@
use llvm; use llvm;
use llvm::AttributePlace::Function; use llvm::AttributePlace::Function;
use rustc::ty::{self, Ty}; use rustc::ty::{self, PolyFnSig};
use rustc::ty::layout::LayoutOf; use rustc::ty::layout::LayoutOf;
use rustc::session::config::Sanitizer; use rustc::session::config::Sanitizer;
use rustc_data_structures::small_c_str::SmallCStr; use rustc_data_structures::small_c_str::SmallCStr;
@ -30,7 +30,6 @@ use rustc_target::spec::PanicStrategy;
use abi::{Abi, FnType, FnTypeExt}; use abi::{Abi, FnType, FnTypeExt};
use attributes; use attributes;
use context::CodegenCx; use context::CodegenCx;
use common;
use type_::Type; use type_::Type;
use value::Value; use value::Value;
@ -129,12 +128,9 @@ pub fn declare_cfn(cx: &CodegenCx<'ll, '_>, name: &str, fn_type: &'ll Type) -> &
pub fn declare_fn( pub fn declare_fn(
cx: &CodegenCx<'ll, 'tcx>, cx: &CodegenCx<'ll, 'tcx>,
name: &str, name: &str,
fn_type: Ty<'tcx>, sig: PolyFnSig<'tcx>,
is_vtable_shim: bool,
) -> &'ll Value { ) -> &'ll Value {
debug!("declare_rust_fn(name={:?}, fn_type={:?}, is_vtable_shim={:?})", debug!("declare_rust_fn(name={:?}, sig={:?})", name, sig);
name, fn_type, is_vtable_shim);
let sig = common::ty_fn_sig_vtable(cx, fn_type, is_vtable_shim);
let sig = cx.tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig); let sig = cx.tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
debug!("declare_rust_fn (after region erasure) sig={:?}", sig); debug!("declare_rust_fn (after region erasure) sig={:?}", sig);
@ -186,12 +182,12 @@ pub fn define_private_global(cx: &CodegenCx<'ll, '_>, ty: &'ll Type) -> &'ll Val
pub fn define_fn( pub fn define_fn(
cx: &CodegenCx<'ll, 'tcx>, cx: &CodegenCx<'ll, 'tcx>,
name: &str, name: &str,
fn_type: Ty<'tcx>, fn_sig: PolyFnSig<'tcx>,
) -> &'ll Value { ) -> &'ll Value {
if get_defined_value(cx, name).is_some() { if get_defined_value(cx, name).is_some() {
cx.sess().fatal(&format!("symbol `{}` already defined", name)) cx.sess().fatal(&format!("symbol `{}` already defined", name))
} else { } else {
declare_fn(cx, name, fn_type, false) declare_fn(cx, name, fn_sig)
} }
} }
@ -203,9 +199,9 @@ pub fn define_fn(
pub fn define_internal_fn( pub fn define_internal_fn(
cx: &CodegenCx<'ll, 'tcx>, cx: &CodegenCx<'ll, 'tcx>,
name: &str, name: &str,
fn_type: Ty<'tcx>, fn_sig: PolyFnSig<'tcx>,
) -> &'ll Value { ) -> &'ll Value {
let llfn = define_fn(cx, name, fn_type); let llfn = define_fn(cx, name, fn_sig);
unsafe { llvm::LLVMRustSetLinkage(llfn, llvm::Linkage::InternalLinkage) }; unsafe { llvm::LLVMRustSetLinkage(llfn, llvm::Linkage::InternalLinkage) };
llfn llfn
} }

View file

@ -933,14 +933,14 @@ fn gen_fn<'ll, 'tcx>(
output: Ty<'tcx>, output: Ty<'tcx>,
codegen: &mut dyn FnMut(Builder<'_, 'll, 'tcx>), codegen: &mut dyn FnMut(Builder<'_, 'll, 'tcx>),
) -> &'ll Value { ) -> &'ll Value {
let rust_fn_ty = cx.tcx.mk_fn_ptr(ty::Binder::bind(cx.tcx.mk_fn_sig( let rust_fn_sig = ty::Binder::bind(cx.tcx.mk_fn_sig(
inputs.into_iter(), inputs.into_iter(),
output, output,
false, false,
hir::Unsafety::Unsafe, hir::Unsafety::Unsafe,
Abi::Rust Abi::Rust
))); ));
let llfn = declare::define_internal_fn(cx, name, rust_fn_ty); let llfn = declare::define_internal_fn(cx, name, rust_fn_sig);
attributes::from_fn_attrs(cx, llfn, None); attributes::from_fn_attrs(cx, llfn, None);
let bx = Builder::new_block(cx, llfn, "entry-block"); let bx = Builder::new_block(cx, llfn, "entry-block");
codegen(bx); codegen(bx);

View file

@ -17,6 +17,7 @@
use asm; use asm;
use attributes; use attributes;
use base; use base;
use common;
use consts; use consts;
use context::CodegenCx; use context::CodegenCx;
use declare; use declare;
@ -154,8 +155,9 @@ fn predefine_fn<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
!instance.substs.has_param_types()); !instance.substs.has_param_types());
let mono_ty = instance.ty(cx.tcx); let mono_ty = instance.ty(cx.tcx);
let mono_sig = common::ty_fn_sig_vtable(cx, mono_ty, instance.is_vtable_shim());
let attrs = cx.tcx.codegen_fn_attrs(instance.def_id()); let attrs = cx.tcx.codegen_fn_attrs(instance.def_id());
let lldecl = declare::declare_fn(cx, symbol_name, mono_ty, instance.is_vtable_shim()); let lldecl = declare::declare_fn(cx, symbol_name, mono_sig);
unsafe { llvm::LLVMRustSetLinkage(lldecl, base::linkage_to_llvm(linkage)) }; unsafe { llvm::LLVMRustSetLinkage(lldecl, base::linkage_to_llvm(linkage)) };
base::set_link_section(lldecl, &attrs); base::set_link_section(lldecl, &attrs);
if linkage == Linkage::LinkOnceODR || if linkage == Linkage::LinkOnceODR ||