@@ -14,10 +14,11 @@ use rustc_middle::ty;
1414use rustc_middle:: ty:: subst:: SubstsRef ;
1515use rustc_middle:: ty:: { Ty , TyCtxt } ;
1616use rustc_span:: symbol:: { sym, Symbol } ;
17- use rustc_target:: abi:: { Abi , LayoutOf as _, Primitive , Size } ;
17+ use rustc_target:: abi:: { Abi , Align , LayoutOf as _, Primitive , Size } ;
1818
1919use super :: {
20- util:: ensure_monomorphic_enough, CheckInAllocMsg , ImmTy , InterpCx , Machine , OpTy , PlaceTy ,
20+ util:: ensure_monomorphic_enough, CheckInAllocMsg , ImmTy , InterpCx , Machine , MemoryKind , OpTy ,
21+ PlaceTy ,
2122} ;
2223
2324mod caller_location;
@@ -337,6 +338,19 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
337338 let result = Scalar :: from_uint ( truncated_bits, layout. size ) ;
338339 self . write_scalar ( result, dest) ?;
339340 }
341+ sym:: const_allocate => {
342+ let size = self . read_scalar ( args[ 0 ] ) ?. to_machine_usize ( self ) ?;
343+ let align = self . read_scalar ( args[ 1 ] ) ?. to_machine_usize ( self ) ?;
344+
345+ let align = match Align :: from_bytes ( align) {
346+ Ok ( a) => a,
347+ Err ( err) => bug ! ( "align has to power of 2, {}" , err) ,
348+ } ;
349+
350+ let ptr =
351+ self . memory . allocate ( Size :: from_bytes ( size as u64 ) , align, MemoryKind :: Heap ) ;
352+ self . write_scalar ( Scalar :: Ptr ( ptr) , dest) ?;
353+ }
340354 sym:: offset => {
341355 let ptr = self . read_scalar ( args[ 0 ] ) ?. check_init ( ) ?;
342356 let offset_count = self . read_scalar ( args[ 1 ] ) ?. to_machine_isize ( self ) ?;
0 commit comments