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