Skip to content

Commit cafebfe

Browse files
committed
A little more cosmetic cleanup
1 parent 1489639 commit cafebfe

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
@@ -229,24 +229,6 @@ fn generic_fields_of(cx: @CrateContext, r: &Repr, sizing: bool)
229229
}
230230
}
231231

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

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

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+
*/
434434
fn build_const_struct(ccx: @CrateContext, st: &Struct, vals: &[ValueRef])
435435
-> ~[ValueRef] {
436436
assert vals.len() == st.fields.len();
@@ -451,12 +451,18 @@ fn build_const_struct(ccx: @CrateContext, st: &Struct, vals: &[ValueRef])
451451
}
452452
assert !is_undef(vals[i]);
453453
// 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.)
454455
cfields.push(vals[i]);
455456
}
456457

457458
return cfields;
458459
}
459460

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

@@ -484,6 +490,7 @@ pub fn const_get_element(ccx: @CrateContext, r: &Repr, val: ValueRef,
484490
}
485491
}
486492

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

0 commit comments

Comments
 (0)