@@ -175,30 +175,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
175
175
. collect:: <Vec <String >>( )
176
176
. join( ", " ) ) ;
177
177
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) ;
202
179
203
180
let bundle = bundle. as_ref ( ) . map ( |b| b. raw ( ) ) . unwrap_or ( 0 as * mut _ ) ;
204
181
@@ -880,30 +857,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
880
857
. collect:: <Vec <String >>( )
881
858
. join( ", " ) ) ;
882
859
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) ;
907
861
908
862
let bundle = bundle. as_ref ( ) . map ( |b| b. raw ( ) ) . unwrap_or ( 0 as * mut _ ) ;
909
863
@@ -1147,3 +1101,30 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1147
1101
}
1148
1102
}
1149
1103
}
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
+ }
0 commit comments