@@ -1065,6 +1065,15 @@ pub fn num_args(r: &Repr, discr: Disr) -> usize {
10651065/// Access a field, at a point when the value's case is known.
10661066pub fn trans_field_ptr < ' blk , ' tcx > ( bcx : Block < ' blk , ' tcx > , r : & Repr < ' tcx > ,
10671067 val : MaybeSizedValue , discr : Disr , ix : usize ) -> ValueRef {
1068+ trans_field_ptr_builder ( & bcx. build ( ) , r, val, discr, ix)
1069+ }
1070+
1071+ /// Access a field, at a point when the value's case is known.
1072+ pub fn trans_field_ptr_builder < ' blk , ' tcx > ( bcx : & BlockAndBuilder < ' blk , ' tcx > ,
1073+ r : & Repr < ' tcx > ,
1074+ val : MaybeSizedValue ,
1075+ discr : Disr , ix : usize )
1076+ -> ValueRef {
10681077 // Note: if this ever needs to generate conditionals (e.g., if we
10691078 // decide to do some kind of cdr-coding-like non-unique repr
10701079 // someday), it will need to return a possibly-new bcx as well.
@@ -1087,13 +1096,15 @@ pub fn trans_field_ptr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, r: &Repr<'tcx>,
10871096 assert_eq ! ( machine:: llsize_of_alloc( bcx. ccx( ) , ty) , 0 ) ;
10881097 // The contents of memory at this pointer can't matter, but use
10891098 // the value that's "reasonable" in case of pointer comparison.
1090- PointerCast ( bcx, val. value , ty. ptr_to ( ) )
1099+ if bcx. is_unreachable ( ) { return C_undef ( ty. ptr_to ( ) ) ; }
1100+ bcx. pointercast ( val. value , ty. ptr_to ( ) )
10911101 }
10921102 RawNullablePointer { nndiscr, nnty, .. } => {
10931103 assert_eq ! ( ix, 0 ) ;
10941104 assert_eq ! ( discr, nndiscr) ;
10951105 let ty = type_of:: type_of ( bcx. ccx ( ) , nnty) ;
1096- PointerCast ( bcx, val. value , ty. ptr_to ( ) )
1106+ if bcx. is_unreachable ( ) { return C_undef ( ty. ptr_to ( ) ) ; }
1107+ bcx. pointercast ( val. value , ty. ptr_to ( ) )
10971108 }
10981109 StructWrappedNullablePointer { ref nonnull, nndiscr, .. } => {
10991110 assert_eq ! ( discr, nndiscr) ;
@@ -1102,33 +1113,39 @@ pub fn trans_field_ptr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, r: &Repr<'tcx>,
11021113 }
11031114}
11041115
1105- pub fn struct_field_ptr < ' blk , ' tcx > ( bcx : Block < ' blk , ' tcx > , st : & Struct < ' tcx > , val : MaybeSizedValue ,
1106- ix : usize , needs_cast : bool ) -> ValueRef {
1116+ fn struct_field_ptr < ' blk , ' tcx > ( bcx : & BlockAndBuilder < ' blk , ' tcx > ,
1117+ st : & Struct < ' tcx > , val : MaybeSizedValue ,
1118+ ix : usize , needs_cast : bool ) -> ValueRef {
11071119 let ccx = bcx. ccx ( ) ;
1120+ let fty = st. fields [ ix] ;
1121+ let ll_fty = type_of:: in_memory_type_of ( bcx. ccx ( ) , fty) ;
1122+ if bcx. is_unreachable ( ) {
1123+ return C_undef ( ll_fty. ptr_to ( ) ) ;
1124+ }
1125+
11081126 let ptr_val = if needs_cast {
11091127 let fields = st. fields . iter ( ) . map ( |& ty| {
11101128 type_of:: in_memory_type_of ( ccx, ty)
11111129 } ) . collect :: < Vec < _ > > ( ) ;
11121130 let real_ty = Type :: struct_ ( ccx, & fields[ ..] , st. packed ) ;
1113- PointerCast ( bcx, val. value , real_ty. ptr_to ( ) )
1131+ bcx. pointercast ( val. value , real_ty. ptr_to ( ) )
11141132 } else {
11151133 val. value
11161134 } ;
11171135
1118- let fty = st. fields [ ix] ;
11191136 // Simple case - we can just GEP the field
11201137 // * First field - Always aligned properly
11211138 // * Packed struct - There is no alignment padding
11221139 // * Field is sized - pointer is properly aligned already
11231140 if ix == 0 || st. packed || type_is_sized ( bcx. tcx ( ) , fty) {
1124- return StructGEP ( bcx, ptr_val, ix) ;
1141+ return bcx. struct_gep ( ptr_val, ix) ;
11251142 }
11261143
11271144 // If the type of the last field is [T] or str, then we don't need to do
11281145 // any adjusments
11291146 match fty. sty {
11301147 ty:: TySlice ( ..) | ty:: TyStr => {
1131- return StructGEP ( bcx, ptr_val, ix) ;
1148+ return bcx. struct_gep ( ptr_val, ix) ;
11321149 }
11331150 _ => ( )
11341151 }
@@ -1137,7 +1154,7 @@ pub fn struct_field_ptr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, st: &Struct<'tcx>, v
11371154 if !val. has_meta ( ) {
11381155 debug ! ( "Unsized field `{}`, of `{:?}` has no metadata for adjustment" ,
11391156 ix, Value ( ptr_val) ) ;
1140- return StructGEP ( bcx, ptr_val, ix) ;
1157+ return bcx. struct_gep ( ptr_val, ix) ;
11411158 }
11421159
11431160 let dbloc = DebugLoc :: None ;
@@ -1178,22 +1195,21 @@ pub fn struct_field_ptr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, st: &Struct<'tcx>, v
11781195 // (unaligned offset + (align - 1)) & -align
11791196
11801197 // Calculate offset
1181- let align_sub_1 = Sub ( bcx, align, C_uint ( bcx. ccx ( ) , 1u64 ) , dbloc) ;
1182- let offset = And ( bcx,
1183- Add ( bcx, unaligned_offset, align_sub_1, dbloc) ,
1184- Neg ( bcx, align, dbloc) ,
1185- dbloc) ;
1198+ dbloc. apply ( bcx. fcx ( ) ) ;
1199+ let align_sub_1 = bcx. sub ( align, C_uint ( bcx. ccx ( ) , 1u64 ) ) ;
1200+ let offset = bcx. and ( bcx. add ( unaligned_offset, align_sub_1) ,
1201+ bcx. neg ( align) ) ;
11861202
11871203 debug ! ( "struct_field_ptr: DST field offset: {:?}" , Value ( offset) ) ;
11881204
11891205 // Cast and adjust pointer
1190- let byte_ptr = PointerCast ( bcx, ptr_val, Type :: i8p ( bcx. ccx ( ) ) ) ;
1191- let byte_ptr = GEP ( bcx, byte_ptr, & [ offset] ) ;
1206+ let byte_ptr = bcx. pointercast ( ptr_val, Type :: i8p ( bcx. ccx ( ) ) ) ;
1207+ let byte_ptr = bcx. gep ( byte_ptr, & [ offset] ) ;
11921208
11931209 // Finally, cast back to the type expected
11941210 let ll_fty = type_of:: in_memory_type_of ( bcx. ccx ( ) , fty) ;
11951211 debug ! ( "struct_field_ptr: Field type is {:?}" , ll_fty) ;
1196- PointerCast ( bcx, byte_ptr, ll_fty. ptr_to ( ) )
1212+ bcx. pointercast ( byte_ptr, ll_fty. ptr_to ( ) )
11971213}
11981214
11991215pub fn fold_variants < ' blk , ' tcx , F > ( bcx : Block < ' blk , ' tcx > ,
@@ -1284,7 +1300,8 @@ pub fn trans_drop_flag_ptr<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
12841300 }
12851301 ) ) ;
12861302 bcx = fold_variants ( bcx, r, val, |variant_cx, st, value| {
1287- let ptr = struct_field_ptr ( variant_cx, st, MaybeSizedValue :: sized ( value) ,
1303+ let ptr = struct_field_ptr ( & variant_cx. build ( ) , st,
1304+ MaybeSizedValue :: sized ( value) ,
12881305 ( st. fields . len ( ) - 1 ) , false ) ;
12891306 datum:: Datum :: new ( ptr, ptr_ty, datum:: Lvalue :: new ( "adt::trans_drop_flag_ptr" ) )
12901307 . store_to ( variant_cx, scratch. val )
0 commit comments