diff options
| author | James Miller <james@aatch.net> | 2016-04-20 18:10:40 +1200 |
|---|---|---|
| committer | James Miller <james@aatch.net> | 2016-04-28 13:18:51 +1200 |
| commit | b5d7783546f938c7c2903b4d5143ff8e8e612674 (patch) | |
| tree | eb54fb028fa6dbe5ee877cca310bacbe0e0d0eb7 | |
| parent | 3bcee269b50def69d73bd588b1619ec6a4756662 (diff) | |
| download | rust-b5d7783546f938c7c2903b4d5143ff8e8e612674.tar.gz rust-b5d7783546f938c7c2903b4d5143ff8e8e612674.zip | |
Check when building invoke as well as calls
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`.
| -rw-r--r-- | src/librustc_trans/builder.rs | 56 |
1 files changed, 41 insertions, 15 deletions
diff --git a/src/librustc_trans/builder.rs b/src/librustc_trans/builder.rs index 92fb342497b..c7de7fd3695 100644 --- a/src/librustc_trans/builder.rs +++ b/src/librustc_trans/builder.rs @@ -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 ({})", @@ -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 { @@ -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); + } } } |
