Skip to content

Commit

Permalink
Check when building invoke as well as calls
Browse files Browse the repository at this point in the history
LLVM's assertion doesn't provide much insight as to what the problem
was. We were already checking `call` instructions ourselves, so this
brings the checks from there to `invoke`.

Both the `invoke` and `call` checking is controlled by
`debug_assertions`.
  • Loading branch information
Aatch committed Apr 28, 2016
1 parent 3bcee26 commit b5d7783
Showing 1 changed file with 41 additions and 15 deletions.
56 changes: 41 additions & 15 deletions src/librustc_trans/builder.rs
Expand Up @@ -165,8 +165,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
args: &[ValueRef],
then: BasicBlockRef,
catch: BasicBlockRef,
bundle: Option<&OperandBundleDef>)
-> ValueRef {
bundle: Option<&OperandBundleDef>) -> ValueRef {
self.count_insn("invoke");

debug!("Invoke {:?} with args ({})",
Expand All @@ -176,6 +175,31 @@ 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);

}
}
}

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

unsafe {
Expand Down Expand Up @@ -856,26 +880,28 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
.collect::<Vec<String>>()
.join(", "));

let mut fn_ty = val_ty(llfn);
// Strip off pointers
while fn_ty.kind() == llvm::TypeKind::Pointer {
fn_ty = fn_ty.element_type();
}
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");
assert!(fn_ty.kind() == llvm::TypeKind::Function,
"builder::call not passed a function");

let param_tys = fn_ty.func_params();
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 {:?}. \
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);

}
}
}

Expand Down

0 comments on commit b5d7783

Please sign in to comment.