Skip to content

Commit 8dca7be

Browse files
committed
A little more cosmetic cleanup
1 parent d6acb96 commit 8dca7be

File tree

1 file changed

+29
-22
lines changed
  • src/librustc/middle/trans

1 file changed

+29
-22
lines changed

src/librustc/middle/trans/adt.rs

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -230,24 +230,6 @@ fn generic_fields_of(cx: @CrateContext, r: &Repr, sizing: bool)
230230
}
231231
}
232232

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-
251233
/**
252234
* Obtain as much of a "discriminant" as this representation has.
253235
* 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)
282264
}
283265
}
284266

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+
285285
/**
286286
* Yield information about how to dispatch a case of the
287287
* discriminant-like value returned by `trans_switch`.
@@ -433,10 +433,10 @@ pub fn trans_const(ccx: @CrateContext, r: &Repr, discr: int,
433433
}
434434
}
435435

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+
*/
440440
fn build_const_struct(ccx: @CrateContext, st: &Struct, vals: &[ValueRef])
441441
-> ~[ValueRef] {
442442
assert vals.len() == st.fields.len();
@@ -457,12 +457,18 @@ fn build_const_struct(ccx: @CrateContext, st: &Struct, vals: &[ValueRef])
457457
}
458458
assert !is_undef(vals[i]);
459459
// 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.)
460461
cfields.push(vals[i]);
461462
}
462463

463464
return cfields;
464465
}
465466

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
466472
#[always_inline]
467473
fn roundup(x: u64, a: u64) -> u64 { ((x + (a - 1)) / a) * a }
468474

@@ -492,6 +498,7 @@ pub fn const_get_element(ccx: @CrateContext, r: &Repr, val: ValueRef,
492498
}
493499
}
494500

501+
/// Extract field of struct-like const, skipping our alignment padding.
495502
fn const_struct_field(ccx: @CrateContext, val: ValueRef, ix: uint)
496503
-> ValueRef {
497504
// Get the ix-th non-undef element of the struct.

0 commit comments

Comments
 (0)