Skip to content

Commit 5bda576

Browse files
committed
Factor out function call checking to a helper method
The logic for checking `call` and `invoke` instructions was duplicated between them, so factor it out to a helper method.
1 parent b5d7783 commit 5bda576

File tree

2 files changed

+30
-49
lines changed

2 files changed

+30
-49
lines changed

src/librustc_trans/builder.rs

+29-48
Original file line numberDiff line numberDiff line change
@@ -175,30 +175,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
175175
.collect::<Vec<String>>()
176176
.join(", "));
177177

178-
if cfg!(debug_assertions) {
179-
let mut fn_ty = val_ty(llfn);
180-
// Strip off pointers
181-
while fn_ty.kind() == llvm::TypeKind::Pointer {
182-
fn_ty = fn_ty.element_type();
183-
}
184-
185-
assert!(fn_ty.kind() == llvm::TypeKind::Function,
186-
"builder::invoke not passed a function");
187-
188-
let param_tys = fn_ty.func_params();
189-
190-
let iter = param_tys.into_iter()
191-
.zip(args.iter().map(|&v| val_ty(v)));
192-
for (i, (expected_ty, actual_ty)) in iter.enumerate() {
193-
if expected_ty != actual_ty {
194-
bug!("Type mismatch in invoke of {:?}. \
195-
Expected {:?} for param {}, got {:?}",
196-
Value(llfn),
197-
expected_ty, i, actual_ty);
198-
199-
}
200-
}
201-
}
178+
check_call("invoke", llfn, args);
202179

203180
let bundle = bundle.as_ref().map(|b| b.raw()).unwrap_or(0 as *mut _);
204181

@@ -880,30 +857,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
880857
.collect::<Vec<String>>()
881858
.join(", "));
882859

883-
if cfg!(debug_assertions) {
884-
let mut fn_ty = val_ty(llfn);
885-
// Strip off pointers
886-
while fn_ty.kind() == llvm::TypeKind::Pointer {
887-
fn_ty = fn_ty.element_type();
888-
}
889-
890-
assert!(fn_ty.kind() == llvm::TypeKind::Function,
891-
"builder::call not passed a function");
892-
893-
let param_tys = fn_ty.func_params();
894-
895-
let iter = param_tys.into_iter()
896-
.zip(args.iter().map(|&v| val_ty(v)));
897-
for (i, (expected_ty, actual_ty)) in iter.enumerate() {
898-
if expected_ty != actual_ty {
899-
bug!("Type mismatch in function call of {:?}. \
900-
Expected {:?} for param {}, got {:?}",
901-
Value(llfn),
902-
expected_ty, i, actual_ty);
903-
904-
}
905-
}
906-
}
860+
check_call("call", llfn, args);
907861

908862
let bundle = bundle.as_ref().map(|b| b.raw()).unwrap_or(0 as *mut _);
909863

@@ -1147,3 +1101,30 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
11471101
}
11481102
}
11491103
}
1104+
1105+
fn check_call(typ: &str, llfn: ValueRef, args: &[ValueRef]) {
1106+
if cfg!(debug_assertions) {
1107+
let mut fn_ty = val_ty(llfn);
1108+
// Strip off pointers
1109+
while fn_ty.kind() == llvm::TypeKind::Pointer {
1110+
fn_ty = fn_ty.element_type();
1111+
}
1112+
1113+
assert!(fn_ty.kind() == llvm::TypeKind::Function,
1114+
"builder::{} not passed a function", typ);
1115+
1116+
let param_tys = fn_ty.func_params();
1117+
1118+
let iter = param_tys.into_iter()
1119+
.zip(args.iter().map(|&v| val_ty(v)));
1120+
for (i, (expected_ty, actual_ty)) in iter.enumerate() {
1121+
if expected_ty != actual_ty {
1122+
bug!("Type mismatch in function call of {:?}. \
1123+
Expected {:?} for param {}, got {:?}",
1124+
Value(llfn),
1125+
expected_ty, i, actual_ty);
1126+
1127+
}
1128+
}
1129+
}
1130+
}

src/librustc_trans/mir/block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
444444
"bad final argument to \"rust-call\" fn {:?}", tuple.ty)
445445
};
446446

447-
// Handle both by-ref and immediate tuples. This gives us the option of
447+
// Handle both by-ref and immediate tuples.
448448
match tuple.val {
449449
Ref(llval) => {
450450
let base_repr = adt::represent_type(bcx.ccx(), tuple.ty);

0 commit comments

Comments
 (0)