@@ -148,16 +148,29 @@ impl<'a, 'tcx> LvalueRef<'tcx> {
148
148
const_llval
149
149
} else {
150
150
let load = bcx. load ( self . llval , self . alignment . non_abi ( ) ) ;
151
- if self . layout . ty . is_bool ( ) {
152
- bcx. range_metadata ( load, 0 ..2 ) ;
153
- } else if self . layout . ty . is_char ( ) {
154
- // a char is a Unicode codepoint, and so takes values from 0
155
- // to 0x10FFFF inclusive only.
156
- bcx. range_metadata ( load, 0 ..0x10FFFF +1 ) ;
157
- } else if self . layout . ty . is_region_ptr ( ) ||
158
- self . layout . ty . is_box ( ) ||
159
- self . layout . ty . is_fn ( ) {
160
- bcx. nonnull_metadata ( load) ;
151
+ if let layout:: Abi :: Scalar ( ref scalar) = self . layout . abi {
152
+ let ( min, max) = ( scalar. valid_range . start , scalar. valid_range . end ) ;
153
+ let max_next = max. wrapping_add ( 1 ) ;
154
+ let bits = scalar. value . size ( bcx. ccx ) . bits ( ) ;
155
+ assert ! ( bits <= 128 ) ;
156
+ let mask = !0u128 >> ( 128 - bits) ;
157
+ // For a (max) value of -1, max will be `-1 as usize`, which overflows.
158
+ // However, that is fine here (it would still represent the full range),
159
+ // i.e., if the range is everything. The lo==hi case would be
160
+ // rejected by the LLVM verifier (it would mean either an
161
+ // empty set, which is impossible, or the entire range of the
162
+ // type, which is pointless).
163
+ match scalar. value {
164
+ layout:: Int ( ..) if max_next & mask != min & mask => {
165
+ // llvm::ConstantRange can deal with ranges that wrap around,
166
+ // so an overflow on (max + 1) is fine.
167
+ bcx. range_metadata ( load, min..max_next) ;
168
+ }
169
+ layout:: Pointer if 0 < min && min < max => {
170
+ bcx. nonnull_metadata ( load) ;
171
+ }
172
+ _ => { }
173
+ }
161
174
}
162
175
load
163
176
} ;
@@ -274,48 +287,18 @@ impl<'a, 'tcx> LvalueRef<'tcx> {
274
287
let cast_to = bcx. ccx . layout_of ( cast_to) . immediate_llvm_type ( bcx. ccx ) ;
275
288
match self . layout . variants {
276
289
layout:: Variants :: Single { index } => {
277
- assert_eq ! ( index, 0 ) ;
278
- return C_uint ( cast_to, 0 ) ;
290
+ return C_uint ( cast_to, index as u64 ) ;
279
291
}
280
292
layout:: Variants :: Tagged { .. } |
281
293
layout:: Variants :: NicheFilling { .. } => { } ,
282
294
}
283
295
284
296
let discr = self . project_field ( bcx, 0 ) ;
285
- let discr_scalar = match discr. layout . abi {
286
- layout:: Abi :: Scalar ( discr) => discr,
287
- _ => bug ! ( "discriminant not scalar: {:#?}" , discr. layout)
288
- } ;
289
- let ( min, max) = match self . layout . variants {
290
- layout:: Variants :: Tagged { ref discr_range, .. } => {
291
- ( discr_range. start , discr_range. end )
292
- }
293
- _ => ( 0 , !0 ) ,
294
- } ;
295
- let max_next = max. wrapping_add ( 1 ) ;
296
- let bits = discr_scalar. size ( bcx. ccx ) . bits ( ) ;
297
- assert ! ( bits <= 128 ) ;
298
- let mask = !0u128 >> ( 128 - bits) ;
299
- let lldiscr = bcx. load ( discr. llval , discr. alignment . non_abi ( ) ) ;
300
- match discr_scalar {
301
- // For a (max) discr of -1, max will be `-1 as usize`, which overflows.
302
- // However, that is fine here (it would still represent the full range),
303
- layout:: Int ( ..) if max_next & mask != min & mask => {
304
- // llvm::ConstantRange can deal with ranges that wrap around,
305
- // so an overflow on (max + 1) is fine.
306
- bcx. range_metadata ( lldiscr, min..max_next) ;
307
- }
308
- _ => {
309
- // i.e., if the range is everything. The lo==hi case would be
310
- // rejected by the LLVM verifier (it would mean either an
311
- // empty set, which is impossible, or the entire range of the
312
- // type, which is pointless).
313
- }
314
- } ;
297
+ let lldiscr = discr. load ( bcx) . immediate ( ) ;
315
298
match self . layout . variants {
316
299
layout:: Variants :: Single { .. } => bug ! ( ) ,
317
- layout:: Variants :: Tagged { .. } => {
318
- let signed = match discr_scalar {
300
+ layout:: Variants :: Tagged { ref discr , .. } => {
301
+ let signed = match discr . value {
319
302
layout:: Int ( _, signed) => signed,
320
303
_ => false
321
304
} ;
0 commit comments