@@ -229,24 +229,6 @@ fn generic_fields_of(cx: @CrateContext, r: &Repr, sizing: bool)
229
229
}
230
230
}
231
231
232
- fn load_discr ( bcx : block , scrutinee : ValueRef , min : int , max : int )
233
- -> ValueRef {
234
- let ptr = GEPi ( bcx, scrutinee, [ 0 , 0 ] ) ;
235
- if max + 1 == min {
236
- // i.e., if the range is everything. The lo==hi case would be
237
- // rejected by the LLVM verifier (it would mean either an
238
- // empty set, which is impossible, or the entire range of the
239
- // type, which is pointless).
240
- Load ( bcx, ptr)
241
- } else {
242
- // llvm::ConstantRange can deal with ranges that wrap around,
243
- // so an overflow on (max + 1) is fine.
244
- LoadRangeAssert ( bcx, ptr, min as c_ulonglong ,
245
- ( max + 1 ) as c_ulonglong ,
246
- /* signed: */ True )
247
- }
248
- }
249
-
250
232
/**
251
233
* Obtain as much of a "discriminant" as this representation has.
252
234
* This should ideally be less tightly tied to `_match`.
@@ -281,6 +263,24 @@ pub fn trans_cast_to_int(bcx: block, r: &Repr, scrutinee: ValueRef)
281
263
}
282
264
}
283
265
266
+ fn load_discr ( bcx : block , scrutinee : ValueRef , min : int , max : int )
267
+ -> ValueRef {
268
+ let ptr = GEPi ( bcx, scrutinee, [ 0 , 0 ] ) ;
269
+ if max + 1 == min {
270
+ // i.e., if the range is everything. The lo==hi case would be
271
+ // rejected by the LLVM verifier (it would mean either an
272
+ // empty set, which is impossible, or the entire range of the
273
+ // type, which is pointless).
274
+ Load ( bcx, ptr)
275
+ } else {
276
+ // llvm::ConstantRange can deal with ranges that wrap around,
277
+ // so an overflow on (max + 1) is fine.
278
+ LoadRangeAssert ( bcx, ptr, min as c_ulonglong ,
279
+ ( max + 1 ) as c_ulonglong ,
280
+ /* signed: */ True )
281
+ }
282
+ }
283
+
284
284
/**
285
285
* Yield information about how to dispatch a case of the
286
286
* discriminant-like value returned by `trans_switch`.
@@ -427,10 +427,10 @@ pub fn trans_const(ccx: @CrateContext, r: &Repr, discr: int,
427
427
}
428
428
}
429
429
430
- fn padding ( size : u64 ) -> ValueRef {
431
- C_undef ( T_array ( T_i8 ( ) , size /*bad*/ as uint ) )
432
- }
433
-
430
+ /**
431
+ * Building structs is a little complicated, because we might need to
432
+ * insert padding if a field's value is less aligned than its type.
433
+ */
434
434
fn build_const_struct ( ccx : @CrateContext , st : & Struct , vals : & [ ValueRef ] )
435
435
-> ~[ ValueRef ] {
436
436
assert vals. len ( ) == st. fields . len ( ) ;
@@ -451,12 +451,18 @@ fn build_const_struct(ccx: @CrateContext, st: &Struct, vals: &[ValueRef])
451
451
}
452
452
assert ! is_undef( vals[ i] ) ;
453
453
// If that assert fails, could change it to wrap in a struct?
454
+ // (See `const_struct_field` for why real fields must not be undef.)
454
455
cfields. push ( vals[ i] ) ;
455
456
}
456
457
457
458
return cfields;
458
459
}
459
460
461
+ fn padding ( size : u64 ) -> ValueRef {
462
+ C_undef ( T_array ( T_i8 ( ) , size /*bad*/ as uint ) )
463
+ }
464
+
465
+ // XXX this utility routine should be somewhere more general
460
466
#[ always_inline]
461
467
fn roundup ( x : u64 , a : u64 ) -> u64 { ( ( x + ( a - 1 ) ) / a) * a }
462
468
@@ -484,6 +490,7 @@ pub fn const_get_element(ccx: @CrateContext, r: &Repr, val: ValueRef,
484
490
}
485
491
}
486
492
493
+ /// Extract field of struct-like const, skipping our alignment padding.
487
494
fn const_struct_field ( ccx: @CrateContext , val: ValueRef , ix: uint)
488
495
-> ValueRef {
489
496
// Get the ix-th non-undef element of the struct.
0 commit comments