@@ -153,6 +153,7 @@ fn build_shim_fn_(ccx: @CrateContext,
153
153
let fcx = new_fn_ctxt ( ccx, ~[ ] , llshimfn, tys. fn_sig . output , None ) ;
154
154
let bcx = top_scope_block ( fcx, None ) ;
155
155
let lltop = bcx. llbb ;
156
+
156
157
let llargbundle = get_param ( llshimfn, 0 u) ;
157
158
let llargvals = arg_builder ( bcx, tys, llargbundle) ;
158
159
@@ -437,11 +438,11 @@ pub fn trans_foreign_mod(ccx: @CrateContext,
437
438
let llbasefn = base_fn ( ccx, * link_name ( ccx, item) , tys, cc) ;
438
439
let ty = ty:: lookup_item_type ( ccx. tcx ,
439
440
ast_util:: local_def ( item. id ) ) . ty ;
441
+ let ret_ty = ty:: ty_fn_ret ( ty) ;
440
442
let args = vec:: from_fn ( ty:: ty_fn_args ( ty) . len ( ) , |i| {
441
- get_param ( decl, i + first_real_arg )
443
+ get_param ( decl, fcx . arg_pos ( i ) )
442
444
} ) ;
443
445
let retval = Call ( bcx, llbasefn, args) ;
444
- let ret_ty = ty:: ty_fn_ret ( ty) ;
445
446
if !ty:: type_is_nil ( ret_ty) && !ty:: type_is_bot ( ret_ty) {
446
447
Store ( bcx, retval, fcx. llretptr . get ( ) ) ;
447
448
}
@@ -465,11 +466,11 @@ pub fn trans_foreign_mod(ccx: @CrateContext,
465
466
set_fixed_stack_segment ( fcx. llfn ) ;
466
467
let ty = ty:: lookup_item_type ( ccx. tcx ,
467
468
ast_util:: local_def ( item. id ) ) . ty ;
469
+ let ret_ty = ty:: ty_fn_ret ( ty) ;
468
470
let args = vec:: from_fn ( ty:: ty_fn_args ( ty) . len ( ) , |i| {
469
- get_param ( decl, i + first_real_arg )
471
+ get_param ( decl, fcx . arg_pos ( i ) )
470
472
} ) ;
471
473
let retval = Call ( bcx, llbasefn, args) ;
472
- let ret_ty = ty:: ty_fn_ret ( ty) ;
473
474
if !ty:: type_is_nil ( ret_ty) && !ty:: type_is_bot ( ret_ty) {
474
475
Store ( bcx, retval, fcx. llretptr . get ( ) ) ;
475
476
}
@@ -512,9 +513,9 @@ pub fn trans_foreign_mod(ccx: @CrateContext,
512
513
let _icx = bcx. insn_ctxt ( "foreign::wrap::build_args" ) ;
513
514
let ccx = bcx. ccx ( ) ;
514
515
let n = tys. llsig . llarg_tys . len ( ) ;
515
- let implicit_args = first_real_arg; // return + env
516
516
for uint:: range( 0 , n) |i| {
517
- let mut llargval = get_param ( llwrapfn, i + implicit_args) ;
517
+ let arg_i = bcx. fcx . arg_pos ( i) ;
518
+ let mut llargval = get_param ( llwrapfn, arg_i) ;
518
519
519
520
// In some cases, Rust will pass a pointer which the
520
521
// native C type doesn't have. In that case, just
@@ -568,6 +569,7 @@ pub fn trans_intrinsic(ccx: @CrateContext,
568
569
569
570
let mut bcx = top_scope_block ( fcx, None ) ;
570
571
let lltop = bcx. llbb ;
572
+ let first_real_arg = fcx. arg_pos ( 0 u) ;
571
573
match * ccx. sess . str_of ( item. ident ) {
572
574
~"atomic_cxchg" => {
573
575
let old = AtomicCmpXchg ( bcx,
@@ -787,7 +789,7 @@ pub fn trans_intrinsic(ccx: @CrateContext,
787
789
let llsrcptr = PointerCast ( bcx, llsrcptr, T_ptr ( T_i8 ( ) ) ) ;
788
790
789
791
let llsize = llsize_of ( ccx, llintype) ;
790
- call_memcpy ( bcx, lldestptr, llsrcptr, llsize) ;
792
+ call_memcpy ( bcx, lldestptr, llsrcptr, llsize, 1 ) ;
791
793
}
792
794
}
793
795
~"needs_drop" => {
@@ -846,44 +848,82 @@ pub fn trans_intrinsic(ccx: @CrateContext,
846
848
Store ( bcx, morestack_addr, fcx. llretptr . get ( ) ) ;
847
849
}
848
850
~"memcpy32" => {
849
- let dst_ptr = get_param ( decl, first_real_arg) ;
850
- let src_ptr = get_param ( decl, first_real_arg + 1 ) ;
851
- let size = get_param ( decl, first_real_arg + 2 ) ;
852
- let align = C_i32 ( 1 ) ;
851
+ let tp_ty = substs. tys [ 0 ] ;
852
+ let lltp_ty = type_of:: type_of ( ccx, tp_ty) ;
853
+ let align = C_i32 ( machine:: llalign_of_min ( ccx, lltp_ty) as i32 ) ;
854
+ let size = C_i32 ( machine:: llsize_of_real ( ccx, lltp_ty) as i32 ) ;
855
+
856
+ let dst_ptr = PointerCast ( bcx, get_param ( decl, first_real_arg) , T_ptr ( T_i8 ( ) ) ) ;
857
+ let src_ptr = PointerCast ( bcx, get_param ( decl, first_real_arg + 1 ) , T_ptr ( T_i8 ( ) ) ) ;
858
+ let count = get_param ( decl, first_real_arg + 2 ) ;
853
859
let volatile = C_i1 ( false ) ;
854
- let llfn = * bcx. ccx ( ) . intrinsics . get (
855
- & ~"llvm. memcpy . p0i8 . p0i8 . i32 ") ;
856
- Call ( bcx, llfn, [ dst_ptr, src_ptr, size, align, volatile] ) ;
860
+ let llfn = * bcx. ccx ( ) . intrinsics . get ( & ~"llvm. memcpy . p0i8 . p0i8 . i32 ") ;
861
+ Call ( bcx, llfn, [ dst_ptr, src_ptr, Mul ( bcx, size, count) , align, volatile] ) ;
857
862
}
858
863
~"memcpy64" => {
859
- let dst_ptr = get_param ( decl, first_real_arg) ;
860
- let src_ptr = get_param ( decl, first_real_arg + 1 ) ;
861
- let size = get_param ( decl, first_real_arg + 2 ) ;
862
- let align = C_i32 ( 1 ) ;
864
+ let tp_ty = substs. tys [ 0 ] ;
865
+ let lltp_ty = type_of:: type_of ( ccx, tp_ty) ;
866
+ let align = C_i32 ( machine:: llalign_of_min ( ccx, lltp_ty) as i32 ) ;
867
+ let size = C_i64 ( machine:: llsize_of_real ( ccx, lltp_ty) as i64 ) ;
868
+
869
+ let dst_ptr = PointerCast ( bcx, get_param ( decl, first_real_arg) , T_ptr ( T_i8 ( ) ) ) ;
870
+ let src_ptr = PointerCast ( bcx, get_param ( decl, first_real_arg + 1 ) , T_ptr ( T_i8 ( ) ) ) ;
871
+ let count = get_param ( decl, first_real_arg + 2 ) ;
863
872
let volatile = C_i1 ( false ) ;
864
- let llfn = * bcx. ccx ( ) . intrinsics . get (
865
- & ~"llvm. memcpy . p0i8 . p0i8 . i64 ") ;
866
- Call ( bcx, llfn, [ dst_ptr, src_ptr, size, align, volatile] ) ;
873
+ let llfn = * bcx. ccx ( ) . intrinsics . get ( & ~"llvm. memcpy . p0i8 . p0i8 . i64 ") ;
874
+ Call ( bcx, llfn, [ dst_ptr, src_ptr, Mul ( bcx, size, count) , align, volatile] ) ;
867
875
}
868
876
~"memmove32" => {
869
- let dst_ptr = get_param ( decl, first_real_arg) ;
870
- let src_ptr = get_param ( decl, first_real_arg + 1 ) ;
871
- let size = get_param ( decl, first_real_arg + 2 ) ;
872
- let align = C_i32 ( 1 ) ;
877
+ let tp_ty = substs. tys [ 0 ] ;
878
+ let lltp_ty = type_of:: type_of ( ccx, tp_ty) ;
879
+ let align = C_i32 ( machine:: llalign_of_min ( ccx, lltp_ty) as i32 ) ;
880
+ let size = C_i32 ( machine:: llsize_of_real ( ccx, lltp_ty) as i32 ) ;
881
+
882
+ let dst_ptr = PointerCast ( bcx, get_param ( decl, first_real_arg) , T_ptr ( T_i8 ( ) ) ) ;
883
+ let src_ptr = PointerCast ( bcx, get_param ( decl, first_real_arg + 1 ) , T_ptr ( T_i8 ( ) ) ) ;
884
+ let count = get_param ( decl, first_real_arg + 2 ) ;
873
885
let volatile = C_i1 ( false ) ;
874
- let llfn = * bcx. ccx ( ) . intrinsics . get (
875
- & ~"llvm. memmove . p0i8 . p0i8 . i32 ") ;
876
- Call ( bcx, llfn, [ dst_ptr, src_ptr, size, align, volatile] ) ;
886
+ let llfn = * bcx. ccx ( ) . intrinsics . get ( & ~"llvm. memmove . p0i8 . p0i8 . i32 ") ;
887
+ Call ( bcx, llfn, [ dst_ptr, src_ptr, Mul ( bcx, size, count) , align, volatile] ) ;
877
888
}
878
889
~"memmove64" => {
879
- let dst_ptr = get_param ( decl, first_real_arg) ;
880
- let src_ptr = get_param ( decl, first_real_arg + 1 ) ;
881
- let size = get_param ( decl, first_real_arg + 2 ) ;
882
- let align = C_i32 ( 1 ) ;
890
+ let tp_ty = substs. tys [ 0 ] ;
891
+ let lltp_ty = type_of:: type_of ( ccx, tp_ty) ;
892
+ let align = C_i32 ( machine:: llalign_of_min ( ccx, lltp_ty) as i32 ) ;
893
+ let size = C_i64 ( machine:: llsize_of_real ( ccx, lltp_ty) as i64 ) ;
894
+
895
+ let dst_ptr = PointerCast ( bcx, get_param ( decl, first_real_arg) , T_ptr ( T_i8 ( ) ) ) ;
896
+ let src_ptr = PointerCast ( bcx, get_param ( decl, first_real_arg + 1 ) , T_ptr ( T_i8 ( ) ) ) ;
897
+ let count = get_param ( decl, first_real_arg + 2 ) ;
898
+ let volatile = C_i1 ( false ) ;
899
+ let llfn = * bcx. ccx ( ) . intrinsics . get ( & ~"llvm. memmove . p0i8 . p0i8 . i64 ") ;
900
+ Call ( bcx, llfn, [ dst_ptr, src_ptr, Mul ( bcx, size, count) , align, volatile] ) ;
901
+ }
902
+ ~"memset32" => {
903
+ let tp_ty = substs. tys [ 0 ] ;
904
+ let lltp_ty = type_of:: type_of ( ccx, tp_ty) ;
905
+ let align = C_i32 ( machine:: llalign_of_min ( ccx, lltp_ty) as i32 ) ;
906
+ let size = C_i32 ( machine:: llsize_of_real ( ccx, lltp_ty) as i32 ) ;
907
+
908
+ let dst_ptr = PointerCast ( bcx, get_param ( decl, first_real_arg) , T_ptr ( T_i8 ( ) ) ) ;
909
+ let val = get_param ( decl, first_real_arg + 1 ) ;
910
+ let count = get_param ( decl, first_real_arg + 2 ) ;
883
911
let volatile = C_i1 ( false ) ;
884
- let llfn = * bcx. ccx ( ) . intrinsics . get (
885
- & ~"llvm. memmove . p0i8 . p0i8 . i64 ") ;
886
- Call ( bcx, llfn, [ dst_ptr, src_ptr, size, align, volatile] ) ;
912
+ let llfn = * bcx. ccx ( ) . intrinsics . get ( & ~"llvm. memset . p0i8 . i32 ") ;
913
+ Call ( bcx, llfn, [ dst_ptr, val, Mul ( bcx, size, count) , align, volatile] ) ;
914
+ }
915
+ ~"memset64" => {
916
+ let tp_ty = substs. tys [ 0 ] ;
917
+ let lltp_ty = type_of:: type_of ( ccx, tp_ty) ;
918
+ let align = C_i32 ( machine:: llalign_of_min ( ccx, lltp_ty) as i32 ) ;
919
+ let size = C_i64 ( machine:: llsize_of_real ( ccx, lltp_ty) as i64 ) ;
920
+
921
+ let dst_ptr = PointerCast ( bcx, get_param ( decl, first_real_arg) , T_ptr ( T_i8 ( ) ) ) ;
922
+ let val = get_param ( decl, first_real_arg + 1 ) ;
923
+ let count = get_param ( decl, first_real_arg + 2 ) ;
924
+ let volatile = C_i1 ( false ) ;
925
+ let llfn = * bcx. ccx ( ) . intrinsics . get ( & ~"llvm. memset . p0i8 . i64 ") ;
926
+ Call ( bcx, llfn, [ dst_ptr, val, Mul ( bcx, size, count) , align, volatile] ) ;
887
927
}
888
928
~"sqrtf32" => {
889
929
let x = get_param ( decl, first_real_arg) ;
@@ -1231,8 +1271,6 @@ pub fn trans_foreign_fn(ccx: @CrateContext,
1231
1271
if !ty:: type_is_immediate ( tys. fn_sig . output ) {
1232
1272
let llretptr = load_inbounds ( bcx, llargbundle, [ 0 u, n] ) ;
1233
1273
llargvals. push ( llretptr) ;
1234
- } else {
1235
- llargvals. push ( C_null ( T_ptr ( T_i8 ( ) ) ) ) ;
1236
1274
}
1237
1275
1238
1276
let llenvptr = C_null ( T_opaque_box_ptr ( bcx. ccx ( ) ) ) ;
0 commit comments