@@ -875,19 +875,17 @@ fn compare_values<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
875
875
debug_loc : DebugLoc )
876
876
-> Result < ' blk , ' tcx > {
877
877
fn compare_str < ' blk , ' tcx > ( cx : Block < ' blk , ' tcx > ,
878
- lhs : ValueRef ,
879
- rhs : ValueRef ,
878
+ lhs_data : ValueRef ,
879
+ lhs_len : ValueRef ,
880
+ rhs_data : ValueRef ,
881
+ rhs_len : ValueRef ,
880
882
rhs_t : Ty < ' tcx > ,
881
883
debug_loc : DebugLoc )
882
884
-> Result < ' blk , ' tcx > {
883
885
let did = langcall ( cx,
884
886
None ,
885
887
& format ! ( "comparison of `{}`" , rhs_t) ,
886
888
StrEqFnLangItem ) ;
887
- let lhs_data = Load ( cx, expr:: get_dataptr ( cx, lhs) ) ;
888
- let lhs_len = Load ( cx, expr:: get_meta ( cx, lhs) ) ;
889
- let rhs_data = Load ( cx, expr:: get_dataptr ( cx, rhs) ) ;
890
- let rhs_len = Load ( cx, expr:: get_meta ( cx, rhs) ) ;
891
889
callee:: trans_lang_call ( cx, did, & [ lhs_data, lhs_len, rhs_data, rhs_len] , None , debug_loc)
892
890
}
893
891
@@ -899,32 +897,38 @@ fn compare_values<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
899
897
900
898
match rhs_t. sty {
901
899
ty:: TyRef ( _, mt) => match mt. ty . sty {
902
- ty:: TyStr => compare_str ( cx, lhs, rhs, rhs_t, debug_loc) ,
900
+ ty:: TyStr => {
901
+ let lhs_data = Load ( cx, expr:: get_dataptr ( cx, lhs) ) ;
902
+ let lhs_len = Load ( cx, expr:: get_meta ( cx, lhs) ) ;
903
+ let rhs_data = Load ( cx, expr:: get_dataptr ( cx, rhs) ) ;
904
+ let rhs_len = Load ( cx, expr:: get_meta ( cx, rhs) ) ;
905
+ compare_str ( cx, lhs_data, lhs_len, rhs_data, rhs_len, rhs_t, debug_loc)
906
+ }
903
907
ty:: TyArray ( ty, _) | ty:: TySlice ( ty) => match ty. sty {
904
908
ty:: TyUint ( ast:: TyU8 ) => {
905
909
// NOTE: cast &[u8] and &[u8; N] to &str and abuse the str_eq lang item,
906
910
// which calls memcmp().
907
911
let pat_len = val_ty ( rhs) . element_type ( ) . array_length ( ) ;
908
912
let ty_str_slice = cx. tcx ( ) . mk_static_str ( ) ;
909
913
910
- let rhs_str = alloc_ty ( cx, ty_str_slice, "rhs_str" ) ;
911
- Store ( cx, expr:: get_dataptr ( cx, rhs) , expr:: get_dataptr ( cx, rhs_str) ) ;
912
- Store ( cx, C_uint ( cx. ccx ( ) , pat_len) , expr:: get_meta ( cx, rhs_str) ) ;
914
+ let rhs_data = GEPi ( cx, rhs, & [ 0 , 0 ] ) ;
915
+ let rhs_len = C_uint ( cx. ccx ( ) , pat_len) ;
913
916
914
- let lhs_str;
917
+ let lhs_data;
918
+ let lhs_len;
915
919
if val_ty ( lhs) == val_ty ( rhs) {
916
920
// Both the discriminant and the pattern are thin pointers
917
- lhs_str = alloc_ty ( cx, ty_str_slice, "lhs_str" ) ;
918
- Store ( cx, expr:: get_dataptr ( cx, lhs) , expr:: get_dataptr ( cx, lhs_str) ) ;
919
- Store ( cx, C_uint ( cx. ccx ( ) , pat_len) , expr:: get_meta ( cx, lhs_str) ) ;
920
- }
921
- else {
921
+ lhs_data = GEPi ( cx, lhs, & [ 0 , 0 ] ) ;
922
+ lhs_len = C_uint ( cx. ccx ( ) , pat_len) ;
923
+ } else {
922
924
// The discriminant is a fat pointer
923
925
let llty_str_slice = type_of:: type_of ( cx. ccx ( ) , ty_str_slice) . ptr_to ( ) ;
924
- lhs_str = PointerCast ( cx, lhs, llty_str_slice) ;
926
+ let lhs_str = PointerCast ( cx, lhs, llty_str_slice) ;
927
+ lhs_data = Load ( cx, expr:: get_dataptr ( cx, lhs_str) ) ;
928
+ lhs_len = Load ( cx, expr:: get_meta ( cx, lhs_str) ) ;
925
929
}
926
930
927
- compare_str ( cx, lhs_str , rhs_str , rhs_t, debug_loc)
931
+ compare_str ( cx, lhs_data , lhs_len , rhs_data , rhs_len , rhs_t, debug_loc)
928
932
} ,
929
933
_ => cx. sess ( ) . bug ( "only byte strings supported in compare_values" ) ,
930
934
} ,
@@ -1192,8 +1196,7 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
1192
1196
let unsized_ty = def. struct_variant ( ) . fields . last ( ) . map ( |field| {
1193
1197
monomorphize:: field_ty ( bcx. tcx ( ) , substs, field)
1194
1198
} ) . unwrap ( ) ;
1195
- let llty = type_of:: type_of ( bcx. ccx ( ) , unsized_ty) ;
1196
- let scratch = alloca_no_lifetime ( bcx, llty, "__struct_field_fat_ptr" ) ;
1199
+ let scratch = alloc_ty ( bcx, unsized_ty, "__struct_field_fat_ptr" ) ;
1197
1200
let data = adt:: trans_field_ptr ( bcx, & * repr, struct_val, 0 , arg_count) ;
1198
1201
let len = Load ( bcx, expr:: get_meta ( bcx, val. val ) ) ;
1199
1202
Store ( bcx, data, expr:: get_dataptr ( bcx, scratch) ) ;
@@ -1520,12 +1523,8 @@ fn create_bindings_map<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, pat: &ast::Pat,
1520
1523
match bm {
1521
1524
ast:: BindByValue ( _) if !moves_by_default || reassigned =>
1522
1525
{
1523
- llmatch = alloca_no_lifetime ( bcx,
1524
- llvariable_ty. ptr_to ( ) ,
1525
- "__llmatch" ) ;
1526
- let llcopy = alloca_no_lifetime ( bcx,
1527
- llvariable_ty,
1528
- & bcx. name ( name) ) ;
1526
+ llmatch = alloca ( bcx, llvariable_ty. ptr_to ( ) , "__llmatch" ) ;
1527
+ let llcopy = alloca ( bcx, llvariable_ty, & bcx. name ( name) ) ;
1529
1528
trmode = if moves_by_default {
1530
1529
TrByMoveIntoCopy ( llcopy)
1531
1530
} else {
@@ -1536,15 +1535,11 @@ fn create_bindings_map<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, pat: &ast::Pat,
1536
1535
// in this case, the final type of the variable will be T,
1537
1536
// but during matching we need to store a *T as explained
1538
1537
// above
1539
- llmatch = alloca_no_lifetime ( bcx,
1540
- llvariable_ty. ptr_to ( ) ,
1541
- & bcx. name ( name) ) ;
1538
+ llmatch = alloca ( bcx, llvariable_ty. ptr_to ( ) , & bcx. name ( name) ) ;
1542
1539
trmode = TrByMoveRef ;
1543
1540
}
1544
1541
ast:: BindByRef ( _) => {
1545
- llmatch = alloca_no_lifetime ( bcx,
1546
- llvariable_ty,
1547
- & bcx. name ( name) ) ;
1542
+ llmatch = alloca ( bcx, llvariable_ty, & bcx. name ( name) ) ;
1548
1543
trmode = TrByRef ;
1549
1544
}
1550
1545
} ;
@@ -1745,6 +1740,7 @@ fn mk_binding_alloca<'blk, 'tcx, A, F>(bcx: Block<'blk, 'tcx>,
1745
1740
1746
1741
// Subtle: be sure that we *populate* the memory *before*
1747
1742
// we schedule the cleanup.
1743
+ call_lifetime_start ( bcx, llval) ;
1748
1744
let bcx = populate ( arg, bcx, datum) ;
1749
1745
bcx. fcx . schedule_lifetime_end ( cleanup_scope, llval) ;
1750
1746
bcx. fcx . schedule_drop_mem ( cleanup_scope, llval, var_ty, lvalue. dropflag_hint ( bcx) ) ;
0 commit comments