@@ -30,17 +30,8 @@ pub(crate) fn codegen_set_discriminant<'tcx>(
3030 } => {
3131 let ptr = place. place_field ( fx, tag_field) ;
3232 let to = layout. ty . discriminant_for_variant ( fx. tcx , variant_index) . unwrap ( ) . val ;
33- let to = match ptr. layout ( ) . ty . kind ( ) {
34- ty:: Uint ( UintTy :: U128 ) | ty:: Int ( IntTy :: I128 ) => {
35- codegen_iconst_u128 ( & mut fx. bcx , to)
36- }
37- ty:: Uint ( _) | ty:: Int ( _) => {
38- let clif_ty = fx. clif_type ( ptr. layout ( ) . ty ) . unwrap ( ) ;
39- let raw_val = ptr. layout ( ) . size . truncate ( to) ;
40- fx. bcx . ins ( ) . iconst ( clif_ty, raw_val as i64 )
41- }
42- _ => unreachable ! ( ) ,
43- } ;
33+ let clif_ty = fx. clif_type ( ptr. layout ( ) . ty ) . unwrap ( ) ;
34+ let to = codegen_iconst_unsigned ( & mut fx. bcx , clif_ty, to) ;
4435 let discr = CValue :: by_val ( to, ptr. layout ( ) ) ;
4536 ptr. write_cvalue ( fx, discr) ;
4637 }
@@ -55,10 +46,7 @@ pub(crate) fn codegen_set_discriminant<'tcx>(
5546 let niche_type = fx. clif_type ( niche. layout ( ) . ty ) . unwrap ( ) ;
5647 let niche_value = variant_index. as_u32 ( ) - niche_variants. start ( ) . as_u32 ( ) ;
5748 let niche_value = ( niche_value as u128 ) . wrapping_add ( niche_start) ;
58- let niche_value = match niche_type {
59- types:: I128 => codegen_iconst_u128 ( & mut fx. bcx , niche_value) ,
60- ty => fx. bcx . ins ( ) . iconst ( ty, niche_value as i64 ) ,
61- } ;
49+ let niche_value = codegen_iconst_unsigned ( & mut fx. bcx , niche_type, niche_value) ;
6250 let niche_llval = CValue :: by_val ( niche_value, niche. layout ( ) ) ;
6351 niche. write_cvalue ( fx, niche_llval) ;
6452 }
@@ -86,17 +74,8 @@ pub(crate) fn codegen_get_discriminant<'tcx>(
8674 . discriminant_for_variant ( fx. tcx , * index)
8775 . map_or ( u128:: from ( index. as_u32 ( ) ) , |discr| discr. val ) ;
8876
89- let val = match dest_layout. ty . kind ( ) {
90- ty:: Uint ( UintTy :: U128 ) | ty:: Int ( IntTy :: I128 ) => {
91- codegen_iconst_u128 ( & mut fx. bcx , discr_val)
92- }
93- ty:: Uint ( _) | ty:: Int ( _) => {
94- let clif_ty = fx. clif_type ( dest_layout. ty ) . unwrap ( ) ;
95- let raw_val = dest_layout. size . truncate ( discr_val) ;
96- fx. bcx . ins ( ) . iconst ( clif_ty, raw_val as i64 )
97- }
98- _ => unreachable ! ( ) ,
99- } ;
77+ let clif_ty = fx. clif_type ( dest_layout. ty ) . unwrap ( ) ;
78+ let val = codegen_iconst_unsigned ( & mut fx. bcx , clif_ty, discr_val) ;
10079 let res = CValue :: by_val ( val, dest_layout) ;
10180 dest. write_cvalue ( fx, res) ;
10281 return ;
@@ -151,16 +130,16 @@ pub(crate) fn codegen_get_discriminant<'tcx>(
151130 // } else {
152131 // untagged_variant
153132 // }
154- let is_niche = codegen_icmp_imm ( fx, IntCC :: Equal , tag, niche_start as i128 ) ;
133+ let is_niche = codegen_icmp_imm ( fx, IntCC :: Equal , tag, niche_start. cast_signed ( ) ) ;
155134 let tagged_discr =
156- fx. bcx . ins ( ) . iconst ( cast_to, niche_variants. start ( ) . as_u32 ( ) as i64 ) ;
135+ fx. bcx . ins ( ) . iconst ( cast_to, i64 :: from ( niche_variants. start ( ) . as_u32 ( ) ) ) ;
157136 ( is_niche, tagged_discr, 0 )
158137 } else {
159138 // The special cases don't apply, so we'll have to go with
160139 // the general algorithm.
161140 let niche_start = match fx. bcx . func . dfg . value_type ( tag) {
162- types :: I128 => codegen_iconst_u128 ( & mut fx . bcx , niche_start ) ,
163- ty => fx. bcx . ins ( ) . iconst ( ty, niche_start as i64 ) ,
141+ // FIXME remove match
142+ ty => codegen_iconst_unsigned ( & mut fx. bcx , ty, niche_start) ,
164143 } ;
165144 let relative_discr = fx. bcx . ins ( ) . isub ( tag, niche_start) ;
166145 let cast_tag = clif_intcast ( fx, relative_discr, cast_to, false ) ;
@@ -177,17 +156,17 @@ pub(crate) fn codegen_get_discriminant<'tcx>(
177156 tagged_discr
178157 } else {
179158 let delta = match cast_to {
180- types :: I128 => codegen_iconst_u128 ( & mut fx . bcx , delta ) ,
181- ty => fx. bcx . ins ( ) . iconst ( ty, delta as i64 ) ,
159+ // FIXME remove match
160+ ty => codegen_iconst_unsigned ( & mut fx. bcx , ty, delta) ,
182161 } ;
183162 fx. bcx . ins ( ) . iadd ( tagged_discr, delta)
184163 } ;
185164
186- let untagged_variant = if cast_to == types :: I128 {
187- codegen_iconst_u128 ( & mut fx. bcx , u128 :: from ( untagged_variant . as_u32 ( ) ) )
188- } else {
189- fx . bcx . ins ( ) . iconst ( cast_to , i64 :: from ( untagged_variant. as_u32 ( ) ) )
190- } ;
165+ let untagged_variant = codegen_iconst_unsigned (
166+ & mut fx. bcx ,
167+ cast_to ,
168+ u128 :: from ( untagged_variant. as_u32 ( ) ) ,
169+ ) ;
191170 let discr = fx. bcx . ins ( ) . select ( is_niche, tagged_discr, untagged_variant) ;
192171 let res = CValue :: by_val ( discr, dest_layout) ;
193172 dest. write_cvalue ( fx, res) ;
0 commit comments