Skip to content

Commit 55b5a36

Browse files
committed
trans: Remove unused return type argument from declare_cfn.
1 parent 5af3c12 commit 55b5a36

File tree

7 files changed

+34
-53
lines changed

7 files changed

+34
-53
lines changed

src/librustc_trans/trans/base.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2630,14 +2630,15 @@ pub fn create_entry_wrapper(ccx: &CrateContext, sp: Span, main_llfn: ValueRef) {
26302630
use_start_lang_item: bool) {
26312631
let llfty = Type::func(&[ccx.int_type(), Type::i8p(ccx).ptr_to()], &ccx.int_type());
26322632

2633-
let llfn = declare::define_cfn(ccx, "main", llfty, ccx.tcx().mk_nil()).unwrap_or_else(|| {
2633+
if declare::get_defined_value(ccx, "main").is_some() {
26342634
// FIXME: We should be smart and show a better diagnostic here.
26352635
ccx.sess().struct_span_err(sp, "entry symbol `main` defined multiple times")
26362636
.help("did you use #[no_mangle] on `fn main`? Use #[start] instead")
26372637
.emit();
26382638
ccx.sess().abort_if_errors();
26392639
panic!();
2640-
});
2640+
}
2641+
let llfn = declare::declare_cfn(ccx, "main", llfty);
26412642

26422643
let llbb = unsafe {
26432644
llvm::LLVMAppendBasicBlockInContext(ccx.llcx(), llfn, "top\0".as_ptr() as *const _)

src/librustc_trans/trans/common.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -519,25 +519,20 @@ impl<'a, 'tcx> FunctionContext<'a, 'tcx> {
519519
Some(def_id) if !base::wants_msvc_seh(ccx.sess()) => {
520520
Callee::def(ccx, def_id, tcx.mk_substs(Substs::empty())).reify(ccx).val
521521
}
522-
_ => {
523-
let mut personality = self.ccx.eh_personality().borrow_mut();
524-
match *personality {
525-
Some(llpersonality) => llpersonality,
526-
None => {
527-
let name = if !base::wants_msvc_seh(self.ccx.sess()) {
528-
"rust_eh_personality"
529-
} else if target.arch == "x86" {
530-
"_except_handler3"
531-
} else {
532-
"__C_specific_handler"
533-
};
534-
let fty = Type::variadic_func(&[], &Type::i32(self.ccx));
535-
let f = declare::declare_cfn(self.ccx, name, fty,
536-
self.ccx.tcx().types.i32);
537-
*personality = Some(f);
538-
f
539-
}
540-
}
522+
_ => if let Some(llpersonality) = ccx.eh_personality().get() {
523+
llpersonality
524+
} else {
525+
let name = if !base::wants_msvc_seh(ccx.sess()) {
526+
"rust_eh_personality"
527+
} else if target.arch == "x86" {
528+
"_except_handler3"
529+
} else {
530+
"__C_specific_handler"
531+
};
532+
let fty = Type::variadic_func(&[], &Type::i32(ccx));
533+
let f = declare::declare_cfn(ccx, name, fty);
534+
ccx.eh_personality().set(Some(f));
535+
f
541536
}
542537
}
543538
}

src/librustc_trans/trans/context.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -865,27 +865,23 @@ fn declare_intrinsic(ccx: &CrateContext, key: &str) -> Option<ValueRef> {
865865
macro_rules! ifn {
866866
($name:expr, fn() -> $ret:expr) => (
867867
if key == $name {
868-
let f = declare::declare_cfn(ccx, $name, Type::func(&[], &$ret),
869-
ccx.tcx().mk_nil());
868+
let f = declare::declare_cfn(ccx, $name, Type::func(&[], &$ret));
870869
llvm::SetUnnamedAddr(f, false);
871870
ccx.intrinsics().borrow_mut().insert($name, f.clone());
872871
return Some(f);
873872
}
874873
);
875874
($name:expr, fn(...) -> $ret:expr) => (
876875
if key == $name {
877-
let f = declare::declare_cfn(ccx, $name,
878-
Type::variadic_func(&[], &$ret),
879-
ccx.tcx().mk_nil());
876+
let f = declare::declare_cfn(ccx, $name, Type::variadic_func(&[], &$ret));
880877
llvm::SetUnnamedAddr(f, false);
881878
ccx.intrinsics().borrow_mut().insert($name, f.clone());
882879
return Some(f);
883880
}
884881
);
885882
($name:expr, fn($($arg:expr),*) -> $ret:expr) => (
886883
if key == $name {
887-
let f = declare::declare_cfn(ccx, $name, Type::func(&[$($arg),*], &$ret),
888-
ccx.tcx().mk_nil());
884+
let f = declare::declare_cfn(ccx, $name, Type::func(&[$($arg),*], &$ret));
889885
llvm::SetUnnamedAddr(f, false);
890886
ccx.intrinsics().borrow_mut().insert($name, f.clone());
891887
return Some(f);
@@ -1032,8 +1028,7 @@ fn declare_intrinsic(ccx: &CrateContext, key: &str) -> Option<ValueRef> {
10321028
ifn!($name, fn($($arg),*) -> void);
10331029
} else if key == $name {
10341030
let f = declare::declare_cfn(ccx, stringify!($cname),
1035-
Type::func(&[$($arg),*], &void),
1036-
ccx.tcx().mk_nil());
1031+
Type::func(&[$($arg),*], &void));
10371032
llvm::SetLinkage(f, llvm::InternalLinkage);
10381033

10391034
let bld = ccx.builder();
@@ -1055,8 +1050,7 @@ fn declare_intrinsic(ccx: &CrateContext, key: &str) -> Option<ValueRef> {
10551050
ifn!($name, fn($($arg),*) -> $ret);
10561051
} else if key == $name {
10571052
let f = declare::declare_cfn(ccx, stringify!($cname),
1058-
Type::func(&[$($arg),*], &$ret),
1059-
ccx.tcx().mk_nil());
1053+
Type::func(&[$($arg),*], &$ret));
10601054
ccx.intrinsics().borrow_mut().insert($name, f.clone());
10611055
return Some(f);
10621056
}

src/librustc_trans/trans/declare.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ pub fn declare_global(ccx: &CrateContext, name: &str, ty: Type) -> llvm::ValueRe
5555
///
5656
/// If there’s a value with the same name already declared, the function will
5757
/// update the declaration and return existing ValueRef instead.
58-
pub fn declare_fn(ccx: &CrateContext, name: &str, callconv: llvm::CallConv,
59-
ty: Type, output: ty::FnOutput) -> ValueRef {
60-
debug!("declare_fn(name={:?})", name);
58+
fn declare_raw_fn(ccx: &CrateContext, name: &str, callconv: llvm::CallConv, ty: Type) -> ValueRef {
59+
debug!("declare_raw_fn(name={:?}, ty={:?})", name, ty);
6160
let namebuf = CString::new(name).unwrap_or_else(|_|{
6261
ccx.sess().bug(&format!("name {:?} contains an interior null byte", name))
6362
});
@@ -70,10 +69,6 @@ pub fn declare_fn(ccx: &CrateContext, name: &str, callconv: llvm::CallConv,
7069
// be merged.
7170
llvm::SetUnnamedAddr(llfn, true);
7271

73-
if output == ty::FnDiverging {
74-
llvm::SetFunctionAttribute(llfn, llvm::Attribute::NoReturn);
75-
}
76-
7772
if ccx.tcx().sess.opts.cg.no_redzone
7873
.unwrap_or(ccx.tcx().sess.target.target.options.disable_redzone) {
7974
llvm::SetFunctionAttribute(llfn, llvm::Attribute::NoRedZone)
@@ -90,9 +85,8 @@ pub fn declare_fn(ccx: &CrateContext, name: &str, callconv: llvm::CallConv,
9085
///
9186
/// If there’s a value with the same name already declared, the function will
9287
/// update the declaration and return existing ValueRef instead.
93-
pub fn declare_cfn(ccx: &CrateContext, name: &str, fn_type: Type,
94-
output: ty::Ty) -> ValueRef {
95-
declare_fn(ccx, name, llvm::CCallConv, fn_type, ty::FnConverging(output))
88+
pub fn declare_cfn(ccx: &CrateContext, name: &str, fn_type: Type) -> ValueRef {
89+
declare_raw_fn(ccx, name, llvm::CCallConv, fn_type)
9690
}
9791

9892

@@ -237,7 +231,7 @@ pub fn define_internal_rust_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
237231

238232
/// Get defined or externally defined (AvailableExternally linkage) value by
239233
/// name.
240-
fn get_defined_value(ccx: &CrateContext, name: &str) -> Option<ValueRef> {
234+
pub fn get_defined_value(ccx: &CrateContext, name: &str) -> Option<ValueRef> {
241235
debug!("get_defined_value(name={:?})", name);
242236
let namebuf = CString::new(name).unwrap_or_else(|_|{
243237
ccx.sess().bug(&format!("name {:?} contains an interior null byte", name))

src/librustc_trans/trans/expr.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,8 +1678,7 @@ fn trans_scalar_binop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
16781678
if use_fmod {
16791679
let f64t = Type::f64(bcx.ccx());
16801680
let fty = Type::func(&[f64t, f64t], &f64t);
1681-
let llfn = declare::declare_cfn(bcx.ccx(), "fmod", fty,
1682-
tcx.types.f64);
1681+
let llfn = declare::declare_cfn(bcx.ccx(), "fmod", fty);
16831682
if lhs_t == tcx.types.f32 {
16841683
let lhs = FPExt(bcx, lhs, f64t);
16851684
let rhs = FPExt(bcx, rhs, f64t);

src/librustc_trans/trans/glue.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
use std;
1616

17-
use back::link::*;
17+
use back::link;
1818
use llvm;
1919
use llvm::{ValueRef, get_param};
2020
use middle::lang_items::ExchangeFreeFnLangItem;
@@ -251,15 +251,14 @@ fn get_drop_glue_core<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
251251
// To avoid infinite recursion, don't `make_drop_glue` until after we've
252252
// added the entry to the `drop_glues` cache.
253253
if let Some(old_sym) = ccx.available_drop_glues().borrow().get(&g) {
254-
let llfn = declare::declare_cfn(ccx, &old_sym, llfnty, ccx.tcx().mk_nil());
254+
let llfn = declare::declare_cfn(ccx, &old_sym, llfnty);
255255
ccx.drop_glues().borrow_mut().insert(g, llfn);
256256
return llfn;
257257
};
258258

259-
let fn_nm = mangle_internal_name_by_type_and_seq(ccx, t, "drop");
260-
let llfn = declare::define_cfn(ccx, &fn_nm, llfnty, ccx.tcx().mk_nil()).unwrap_or_else(||{
261-
ccx.sess().bug(&format!("symbol `{}` already defined", fn_nm));
262-
});
259+
let fn_nm = link::mangle_internal_name_by_type_and_seq(ccx, t, "drop");
260+
assert!(declare::get_defined_value(ccx, &fn_nm).is_none());
261+
let llfn = declare::declare_cfn(ccx, &fn_nm, llfnty);
263262
ccx.available_drop_glues().borrow_mut().insert(g, fn_nm);
264263

265264
let _s = StatRecorder::new(ccx, format!("drop {:?}", t));

src/librustc_trans/trans/intrinsic.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -949,8 +949,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
949949
intrinsics::IntrinsicDef::Named(name) => {
950950
let f = declare::declare_cfn(ccx,
951951
name,
952-
Type::func(&inputs, &outputs),
953-
tcx.mk_nil());
952+
Type::func(&inputs, &outputs));
954953
Call(bcx, f, &llargs, None, call_debug_location)
955954
}
956955
};

0 commit comments

Comments
 (0)