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

trans: Remove unused return type argument from declare_cfn.

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