提交 55b5a365 编写于 作者: E Eduard Burtescu

trans: Remove unused return type argument from declare_cfn.

上级 5af3c12c
......@@ -2630,14 +2630,15 @@ fn create_entry_fn(ccx: &CrateContext,
use_start_lang_item: bool) {
let llfty = Type::func(&[ccx.int_type(), Type::i8p(ccx).ptr_to()], &ccx.int_type());
let llfn = declare::define_cfn(ccx, "main", llfty, ccx.tcx().mk_nil()).unwrap_or_else(|| {
if declare::get_defined_value(ccx, "main").is_some() {
// FIXME: We should be smart and show a better diagnostic here.
ccx.sess().struct_span_err(sp, "entry symbol `main` defined multiple times")
.help("did you use #[no_mangle] on `fn main`? Use #[start] instead")
.emit();
ccx.sess().abort_if_errors();
panic!();
});
}
let llfn = declare::declare_cfn(ccx, "main", llfty);
let llbb = unsafe {
llvm::LLVMAppendBasicBlockInContext(ccx.llcx(), llfn, "top\0".as_ptr() as *const _)
......
......@@ -519,28 +519,23 @@ pub fn eh_personality(&self) -> ValueRef {
Some(def_id) if !base::wants_msvc_seh(ccx.sess()) => {
Callee::def(ccx, def_id, tcx.mk_substs(Substs::empty())).reify(ccx).val
}
_ => {
let mut personality = self.ccx.eh_personality().borrow_mut();
match *personality {
Some(llpersonality) => llpersonality,
None => {
let name = if !base::wants_msvc_seh(self.ccx.sess()) {
_ => if let Some(llpersonality) = ccx.eh_personality().get() {
llpersonality
} else {
let name = if !base::wants_msvc_seh(ccx.sess()) {
"rust_eh_personality"
} else if target.arch == "x86" {
"_except_handler3"
} else {
"__C_specific_handler"
};
let fty = Type::variadic_func(&[], &Type::i32(self.ccx));
let f = declare::declare_cfn(self.ccx, name, fty,
self.ccx.tcx().types.i32);
*personality = Some(f);
let fty = Type::variadic_func(&[], &Type::i32(ccx));
let f = declare::declare_cfn(ccx, name, fty);
ccx.eh_personality().set(Some(f));
f
}
}
}
}
}
// Returns a ValueRef of the "eh_unwind_resume" lang item if one is defined,
// otherwise declares it as an external function.
......
......@@ -865,8 +865,7 @@ fn declare_intrinsic(ccx: &CrateContext, key: &str) -> Option<ValueRef> {
macro_rules! ifn {
($name:expr, fn() -> $ret:expr) => (
if key == $name {
let f = declare::declare_cfn(ccx, $name, Type::func(&[], &$ret),
ccx.tcx().mk_nil());
let f = declare::declare_cfn(ccx, $name, Type::func(&[], &$ret));
llvm::SetUnnamedAddr(f, false);
ccx.intrinsics().borrow_mut().insert($name, f.clone());
return Some(f);
......@@ -874,9 +873,7 @@ fn declare_intrinsic(ccx: &CrateContext, key: &str) -> Option<ValueRef> {
);
($name:expr, fn(...) -> $ret:expr) => (
if key == $name {
let f = declare::declare_cfn(ccx, $name,
Type::variadic_func(&[], &$ret),
ccx.tcx().mk_nil());
let f = declare::declare_cfn(ccx, $name, Type::variadic_func(&[], &$ret));
llvm::SetUnnamedAddr(f, false);
ccx.intrinsics().borrow_mut().insert($name, f.clone());
return Some(f);
......@@ -884,8 +881,7 @@ fn declare_intrinsic(ccx: &CrateContext, key: &str) -> Option<ValueRef> {
);
($name:expr, fn($($arg:expr),*) -> $ret:expr) => (
if key == $name {
let f = declare::declare_cfn(ccx, $name, Type::func(&[$($arg),*], &$ret),
ccx.tcx().mk_nil());
let f = declare::declare_cfn(ccx, $name, Type::func(&[$($arg),*], &$ret));
llvm::SetUnnamedAddr(f, false);
ccx.intrinsics().borrow_mut().insert($name, f.clone());
return Some(f);
......@@ -1032,8 +1028,7 @@ fn declare_intrinsic(ccx: &CrateContext, key: &str) -> Option<ValueRef> {
ifn!($name, fn($($arg),*) -> void);
} else if key == $name {
let f = declare::declare_cfn(ccx, stringify!($cname),
Type::func(&[$($arg),*], &void),
ccx.tcx().mk_nil());
Type::func(&[$($arg),*], &void));
llvm::SetLinkage(f, llvm::InternalLinkage);
let bld = ccx.builder();
......@@ -1055,8 +1050,7 @@ fn declare_intrinsic(ccx: &CrateContext, key: &str) -> Option<ValueRef> {
ifn!($name, fn($($arg),*) -> $ret);
} else if key == $name {
let f = declare::declare_cfn(ccx, stringify!($cname),
Type::func(&[$($arg),*], &$ret),
ccx.tcx().mk_nil());
Type::func(&[$($arg),*], &$ret));
ccx.intrinsics().borrow_mut().insert($name, f.clone());
return Some(f);
}
......
......@@ -55,9 +55,8 @@ pub fn declare_global(ccx: &CrateContext, name: &str, ty: Type) -> llvm::ValueRe
///
/// If there’s a value with the same name already declared, the function will
/// update the declaration and return existing ValueRef instead.
pub fn declare_fn(ccx: &CrateContext, name: &str, callconv: llvm::CallConv,
ty: Type, output: ty::FnOutput) -> ValueRef {
debug!("declare_fn(name={:?})", name);
fn declare_raw_fn(ccx: &CrateContext, name: &str, callconv: llvm::CallConv, ty: Type) -> ValueRef {
debug!("declare_raw_fn(name={:?}, ty={:?})", name, ty);
let namebuf = CString::new(name).unwrap_or_else(|_|{
ccx.sess().bug(&format!("name {:?} contains an interior null byte", name))
});
......@@ -70,10 +69,6 @@ pub fn declare_fn(ccx: &CrateContext, name: &str, callconv: llvm::CallConv,
// be merged.
llvm::SetUnnamedAddr(llfn, true);
if output == ty::FnDiverging {
llvm::SetFunctionAttribute(llfn, llvm::Attribute::NoReturn);
}
if ccx.tcx().sess.opts.cg.no_redzone
.unwrap_or(ccx.tcx().sess.target.target.options.disable_redzone) {
llvm::SetFunctionAttribute(llfn, llvm::Attribute::NoRedZone)
......@@ -90,9 +85,8 @@ pub fn declare_fn(ccx: &CrateContext, name: &str, callconv: llvm::CallConv,
///
/// If there’s a value with the same name already declared, the function will
/// update the declaration and return existing ValueRef instead.
pub fn declare_cfn(ccx: &CrateContext, name: &str, fn_type: Type,
output: ty::Ty) -> ValueRef {
declare_fn(ccx, name, llvm::CCallConv, fn_type, ty::FnConverging(output))
pub fn declare_cfn(ccx: &CrateContext, name: &str, fn_type: Type) -> ValueRef {
declare_raw_fn(ccx, name, llvm::CCallConv, fn_type)
}
......@@ -237,7 +231,7 @@ pub fn define_internal_rust_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
/// Get defined or externally defined (AvailableExternally linkage) value by
/// name.
fn get_defined_value(ccx: &CrateContext, name: &str) -> Option<ValueRef> {
pub fn get_defined_value(ccx: &CrateContext, name: &str) -> Option<ValueRef> {
debug!("get_defined_value(name={:?})", name);
let namebuf = CString::new(name).unwrap_or_else(|_|{
ccx.sess().bug(&format!("name {:?} contains an interior null byte", name))
......
......@@ -1678,8 +1678,7 @@ fn trans_scalar_binop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
if use_fmod {
let f64t = Type::f64(bcx.ccx());
let fty = Type::func(&[f64t, f64t], &f64t);
let llfn = declare::declare_cfn(bcx.ccx(), "fmod", fty,
tcx.types.f64);
let llfn = declare::declare_cfn(bcx.ccx(), "fmod", fty);
if lhs_t == tcx.types.f32 {
let lhs = FPExt(bcx, lhs, f64t);
let rhs = FPExt(bcx, rhs, f64t);
......
......@@ -14,7 +14,7 @@
use std;
use back::link::*;
use back::link;
use llvm;
use llvm::{ValueRef, get_param};
use middle::lang_items::ExchangeFreeFnLangItem;
......@@ -251,15 +251,14 @@ fn get_drop_glue_core<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
// To avoid infinite recursion, don't `make_drop_glue` until after we've
// added the entry to the `drop_glues` cache.
if let Some(old_sym) = ccx.available_drop_glues().borrow().get(&g) {
let llfn = declare::declare_cfn(ccx, &old_sym, llfnty, ccx.tcx().mk_nil());
let llfn = declare::declare_cfn(ccx, &old_sym, llfnty);
ccx.drop_glues().borrow_mut().insert(g, llfn);
return llfn;
};
let fn_nm = mangle_internal_name_by_type_and_seq(ccx, t, "drop");
let llfn = declare::define_cfn(ccx, &fn_nm, llfnty, ccx.tcx().mk_nil()).unwrap_or_else(||{
ccx.sess().bug(&format!("symbol `{}` already defined", fn_nm));
});
let fn_nm = link::mangle_internal_name_by_type_and_seq(ccx, t, "drop");
assert!(declare::get_defined_value(ccx, &fn_nm).is_none());
let llfn = declare::declare_cfn(ccx, &fn_nm, llfnty);
ccx.available_drop_glues().borrow_mut().insert(g, fn_nm);
let _s = StatRecorder::new(ccx, format!("drop {:?}", t));
......
......@@ -949,8 +949,7 @@ fn modify_as_needed<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
intrinsics::IntrinsicDef::Named(name) => {
let f = declare::declare_cfn(ccx,
name,
Type::func(&inputs, &outputs),
tcx.mk_nil());
Type::func(&inputs, &outputs));
Call(bcx, f, &llargs, None, call_debug_location)
}
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册