@@ -10,7 +10,7 @@ use rustc_data_structures::profiling::SelfProfilerRef;
1010use rustc_index:: IndexVec ;
1111use rustc_middle:: ty:: TypeVisitableExt ;
1212use rustc_middle:: ty:: adjustment:: PointerCoercion ;
13- use rustc_middle:: ty:: layout:: FnAbiOf ;
13+ use rustc_middle:: ty:: layout:: { FnAbiOf , HasTypingEnv as _ } ;
1414use rustc_middle:: ty:: print:: with_no_trimmed_paths;
1515use rustc_session:: config:: OutputFilenames ;
1616use rustc_span:: Symbol ;
@@ -924,19 +924,26 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
924924 count,
925925 } ) => {
926926 let dst = codegen_operand ( fx, dst) ;
927- let pointee = dst
928- . layout ( )
929- . pointee_info_at ( fx, rustc_abi:: Size :: ZERO )
930- . expect ( "Expected pointer" ) ;
927+
928+ let & ty:: RawPtr ( pointee, _) = dst. layout ( ) . ty . kind ( ) else {
929+ bug ! ( "expected pointer" )
930+ } ;
931+ let pointee_layout = fx
932+ . tcx
933+ . layout_of ( fx. typing_env ( ) . as_query_input ( pointee) )
934+ . expect ( "expected pointee to have a layout" ) ;
935+ let elem_size: u64 = pointee_layout. layout . size ( ) . bytes ( ) ;
936+
931937 let dst = dst. load_scalar ( fx) ;
932938 let src = codegen_operand ( fx, src) . load_scalar ( fx) ;
933939 let count = codegen_operand ( fx, count) . load_scalar ( fx) ;
934- let elem_size : u64 = pointee . size . bytes ( ) ;
940+
935941 let bytes = if elem_size != 1 {
936942 fx. bcx . ins ( ) . imul_imm ( count, elem_size as i64 )
937943 } else {
938944 count
939945 } ;
946+
940947 fx. bcx . call_memcpy ( fx. target_config , dst, src, bytes) ;
941948 }
942949 } ,
0 commit comments