@@ -8,10 +8,12 @@ use libffi::middle::Type as FfiType;
88use rustc_abi:: { HasDataLayout , Size } ;
99use rustc_data_structures:: either;
1010use rustc_middle:: ty:: layout:: { HasTypingEnv , TyAndLayout } ;
11- use rustc_middle:: ty:: { self , IntTy , Ty , UintTy } ;
11+ use rustc_middle:: ty:: { self , FloatTy , IntTy , Ty , UintTy } ;
1212use rustc_span:: Symbol ;
1313use serde:: { Deserialize , Serialize } ;
1414
15+ use self :: helpers:: ToSoft ;
16+
1517mod ffi;
1618
1719#[ cfg_attr(
@@ -138,6 +140,14 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
138140 let x = unsafe { ffi:: call :: < usize > ( fun, libffi_args) } ;
139141 Scalar :: from_target_usize ( x. try_into ( ) . unwrap ( ) , this)
140142 }
143+ ty:: Float ( FloatTy :: F32 ) => {
144+ let x = unsafe { ffi:: call :: < f32 > ( fun, libffi_args) } ;
145+ Scalar :: from_f32 ( x. to_soft ( ) )
146+ }
147+ ty:: Float ( FloatTy :: F64 ) => {
148+ let x = unsafe { ffi:: call :: < f64 > ( fun, libffi_args) } ;
149+ Scalar :: from_f64 ( x. to_soft ( ) )
150+ }
141151 // Functions with no declared return type (i.e., the default return)
142152 // have the output_type `Tuple([])`.
143153 ty:: Tuple ( t_list) if ( * t_list) . deref ( ) . is_empty ( ) => {
@@ -396,7 +406,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
396406
397407 /// Gets the matching libffi type for a given Ty.
398408 fn ty_to_ffitype ( & self , layout : TyAndLayout < ' tcx > ) -> InterpResult < ' tcx , FfiType > {
399- use rustc_abi:: { AddressSpace , BackendRepr , Integer , Primitive } ;
409+ use rustc_abi:: { AddressSpace , BackendRepr , Float , Integer , Primitive } ;
400410
401411 // `BackendRepr::Scalar` is also a signal to pass this type as a scalar in the ABI. This
402412 // matches what codegen does. This does mean that we support some types whose ABI is not
@@ -413,6 +423,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
413423 Primitive :: Int ( Integer :: I16 , /* signed */ false ) => FfiType :: u16 ( ) ,
414424 Primitive :: Int ( Integer :: I32 , /* signed */ false ) => FfiType :: u32 ( ) ,
415425 Primitive :: Int ( Integer :: I64 , /* signed */ false ) => FfiType :: u64 ( ) ,
426+ Primitive :: Float ( Float :: F32 ) => FfiType :: f32 ( ) ,
427+ Primitive :: Float ( Float :: F64 ) => FfiType :: f64 ( ) ,
416428 Primitive :: Pointer ( AddressSpace :: ZERO ) => FfiType :: pointer ( ) ,
417429 _ =>
418430 throw_unsup_format ! (
0 commit comments