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.
This commit is contained in:
parent
b5d7783546
commit
5bda576cd6
2 changed files with 30 additions and 49 deletions
|
@ -175,30 +175,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
.collect::<Vec<String>>()
|
||||
.join(", "));
|
||||
|
||||
if cfg!(debug_assertions) {
|
||||
let mut fn_ty = val_ty(llfn);
|
||||
// Strip off pointers
|
||||
while fn_ty.kind() == llvm::TypeKind::Pointer {
|
||||
fn_ty = fn_ty.element_type();
|
||||
}
|
||||
|
||||
assert!(fn_ty.kind() == llvm::TypeKind::Function,
|
||||
"builder::invoke not passed a function");
|
||||
|
||||
let param_tys = fn_ty.func_params();
|
||||
|
||||
let iter = param_tys.into_iter()
|
||||
.zip(args.iter().map(|&v| val_ty(v)));
|
||||
for (i, (expected_ty, actual_ty)) in iter.enumerate() {
|
||||
if expected_ty != actual_ty {
|
||||
bug!("Type mismatch in invoke of {:?}. \
|
||||
Expected {:?} for param {}, got {:?}",
|
||||
Value(llfn),
|
||||
expected_ty, i, actual_ty);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
check_call("invoke", llfn, args);
|
||||
|
||||
let bundle = bundle.as_ref().map(|b| b.raw()).unwrap_or(0 as *mut _);
|
||||
|
||||
|
@ -880,30 +857,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
.collect::<Vec<String>>()
|
||||
.join(", "));
|
||||
|
||||
if cfg!(debug_assertions) {
|
||||
let mut fn_ty = val_ty(llfn);
|
||||
// Strip off pointers
|
||||
while fn_ty.kind() == llvm::TypeKind::Pointer {
|
||||
fn_ty = fn_ty.element_type();
|
||||
}
|
||||
|
||||
assert!(fn_ty.kind() == llvm::TypeKind::Function,
|
||||
"builder::call not passed a function");
|
||||
|
||||
let param_tys = fn_ty.func_params();
|
||||
|
||||
let iter = param_tys.into_iter()
|
||||
.zip(args.iter().map(|&v| val_ty(v)));
|
||||
for (i, (expected_ty, actual_ty)) in iter.enumerate() {
|
||||
if expected_ty != actual_ty {
|
||||
bug!("Type mismatch in function call of {:?}. \
|
||||
Expected {:?} for param {}, got {:?}",
|
||||
Value(llfn),
|
||||
expected_ty, i, actual_ty);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
check_call("call", llfn, args);
|
||||
|
||||
let bundle = bundle.as_ref().map(|b| b.raw()).unwrap_or(0 as *mut _);
|
||||
|
||||
|
@ -1147,3 +1101,30 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn check_call(typ: &str, llfn: ValueRef, args: &[ValueRef]) {
|
||||
if cfg!(debug_assertions) {
|
||||
let mut fn_ty = val_ty(llfn);
|
||||
// Strip off pointers
|
||||
while fn_ty.kind() == llvm::TypeKind::Pointer {
|
||||
fn_ty = fn_ty.element_type();
|
||||
}
|
||||
|
||||
assert!(fn_ty.kind() == llvm::TypeKind::Function,
|
||||
"builder::{} not passed a function", typ);
|
||||
|
||||
let param_tys = fn_ty.func_params();
|
||||
|
||||
let iter = param_tys.into_iter()
|
||||
.zip(args.iter().map(|&v| val_ty(v)));
|
||||
for (i, (expected_ty, actual_ty)) in iter.enumerate() {
|
||||
if expected_ty != actual_ty {
|
||||
bug!("Type mismatch in function call of {:?}. \
|
||||
Expected {:?} for param {}, got {:?}",
|
||||
Value(llfn),
|
||||
expected_ty, i, actual_ty);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -444,7 +444,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
|
|||
"bad final argument to \"rust-call\" fn {:?}", tuple.ty)
|
||||
};
|
||||
|
||||
// Handle both by-ref and immediate tuples. This gives us the option of
|
||||
// Handle both by-ref and immediate tuples.
|
||||
match tuple.val {
|
||||
Ref(llval) => {
|
||||
let base_repr = adt::represent_type(bcx.ccx(), tuple.ty);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue