@@ -173,35 +173,31 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
173173 "frem_fast" => mir:: BinOp :: Rem ,
174174 _ => bug ! ( ) ,
175175 } ;
176- let a_valid = match a. layout . ty . kind ( ) {
177- ty:: Float ( FloatTy :: F32 ) => a. to_scalar ( ) ?. to_f32 ( ) ?. is_finite ( ) ,
178- ty:: Float ( FloatTy :: F64 ) => a. to_scalar ( ) ?. to_f64 ( ) ?. is_finite ( ) ,
179- _ => bug ! (
180- "`{}` called with non-float input type {:?}" ,
176+ let float_finite = |x : ImmTy < ' tcx , _ > | -> InterpResult < ' tcx , bool > {
177+ Ok ( match x. layout . ty . kind ( ) {
178+ ty:: Float ( FloatTy :: F32 ) => x. to_scalar ( ) ?. to_f32 ( ) ?. is_finite ( ) ,
179+ ty:: Float ( FloatTy :: F64 ) => x. to_scalar ( ) ?. to_f64 ( ) ?. is_finite ( ) ,
180+ _ => bug ! (
181+ "`{}` called with non-float input type {:?}" ,
182+ intrinsic_name,
183+ x. layout. ty
184+ ) ,
185+ } )
186+ } ;
187+ match ( float_finite ( a) ?, float_finite ( b) ?) {
188+ ( false , false ) => throw_ub_format ! (
189+ "`{}` intrinsic called with non-finite value as both parameters" ,
181190 intrinsic_name,
182- a. layout. ty
183191 ) ,
184- } ;
185- if !a_valid {
186- throw_ub_format ! (
192+ ( false , _) => throw_ub_format ! (
187193 "`{}` intrinsic called with non-finite value as first parameter" ,
188194 intrinsic_name,
189- ) ;
190- }
191- let b_valid = match b. layout . ty . kind ( ) {
192- ty:: Float ( FloatTy :: F32 ) => b. to_scalar ( ) ?. to_f32 ( ) ?. is_finite ( ) ,
193- ty:: Float ( FloatTy :: F64 ) => b. to_scalar ( ) ?. to_f64 ( ) ?. is_finite ( ) ,
194- _ => bug ! (
195- "`{}` called with non-float input type {:?}" ,
196- intrinsic_name,
197- b. layout. ty
198195 ) ,
199- } ;
200- if !b_valid {
201- throw_ub_format ! (
196+ ( _, false ) => throw_ub_format ! (
202197 "`{}` intrinsic called with non-finite value as second parameter" ,
203198 intrinsic_name,
204- ) ;
199+ ) ,
200+ _ => { }
205201 }
206202 this. binop_ignore_overflow ( op, & a, & b, dest) ?;
207203 }
0 commit comments