Skip to content

Commit b5d7783

Browse files
committed
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`.
1 parent 3bcee26 commit b5d7783

File tree

1 file changed

+41
-15
lines changed

1 file changed

+41
-15
lines changed

src/librustc_trans/builder.rs

+41-15
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
165165
args: &[ValueRef],
166166
then: BasicBlockRef,
167167
catch: BasicBlockRef,
168-
bundle: Option<&OperandBundleDef>)
169-
-> ValueRef {
168+
bundle: Option<&OperandBundleDef>) -> ValueRef {
170169
self.count_insn("invoke");
171170

172171
debug!("Invoke {:?} with args ({})",
@@ -176,6 +175,31 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
176175
.collect::<Vec<String>>()
177176
.join(", "));
178177

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+
}
202+
179203
let bundle = bundle.as_ref().map(|b| b.raw()).unwrap_or(0 as *mut _);
180204

181205
unsafe {
@@ -856,26 +880,28 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
856880
.collect::<Vec<String>>()
857881
.join(", "));
858882

859-
let mut fn_ty = val_ty(llfn);
860-
// Strip off pointers
861-
while fn_ty.kind() == llvm::TypeKind::Pointer {
862-
fn_ty = fn_ty.element_type();
863-
}
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+
}
864889

865-
assert!(fn_ty.kind() == llvm::TypeKind::Function,
866-
"builder::call not passed a function");
890+
assert!(fn_ty.kind() == llvm::TypeKind::Function,
891+
"builder::call not passed a function");
867892

868-
let param_tys = fn_ty.func_params();
893+
let param_tys = fn_ty.func_params();
869894

870-
let iter = param_tys.into_iter()
871-
.zip(args.iter().map(|&v| val_ty(v)));
872-
for (i, (expected_ty, actual_ty)) in iter.enumerate() {
873-
if expected_ty != actual_ty {
874-
bug!("Type mismatch in function call of {:?}. \
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 {:?}. \
875900
Expected {:?} for param {}, got {:?}",
876901
Value(llfn),
877902
expected_ty, i, actual_ty);
878903

904+
}
879905
}
880906
}
881907

0 commit comments

Comments
 (0)