Don't truncate discriminants to host uint for C_uint's sake.

This commit is contained in:
Jed Davis 2013-08-02 12:24:21 -07:00
parent 8ef8dd9ceb
commit 5f536efa9f
3 changed files with 13 additions and 9 deletions

View File

@ -306,7 +306,7 @@ pub fn trans_get_discr(bcx: @mut Block, r: &Repr, scrutinee: ValueRef)
-> ValueRef {
match *r {
CEnum(min, max) => load_discr(bcx, scrutinee, min, max),
Univariant(*) => C_uint(bcx.ccx(), 0),
Univariant(*) => C_disr(bcx.ccx(), 0),
General(ref cases) => load_discr(bcx, scrutinee, 0, (cases.len() - 1) as Disr),
NullablePointer{ nonnull: ref nonnull, nndiscr, ptrfield, _ } => {
ZExt(bcx, nullable_bitdiscr(bcx, nonnull, nndiscr, ptrfield, scrutinee),
@ -351,13 +351,13 @@ fn load_discr(bcx: @mut Block, scrutinee: ValueRef, min: Disr, max: Disr)
pub fn trans_case(bcx: @mut Block, r: &Repr, discr: Disr) -> _match::opt_result {
match *r {
CEnum(*) => {
_match::single_result(rslt(bcx, C_uint(bcx.ccx(), discr /*bad*/as uint)))
_match::single_result(rslt(bcx, C_disr(bcx.ccx(), discr)))
}
Univariant(*) => {
bcx.ccx().sess.bug("no cases for univariants or structs")
}
General(*) => {
_match::single_result(rslt(bcx, C_uint(bcx.ccx(), discr /*bad*/as uint)))
_match::single_result(rslt(bcx, C_disr(bcx.ccx(), discr)))
}
NullablePointer{ _ } => {
assert!(discr == 0 || discr == 1);
@ -375,7 +375,7 @@ pub fn trans_start_init(bcx: @mut Block, r: &Repr, val: ValueRef, discr: Disr) {
match *r {
CEnum(min, max) => {
assert!(min <= discr && discr <= max);
Store(bcx, C_uint(bcx.ccx(), discr/*bad*/ as uint), GEPi(bcx, val, [0, 0]))
Store(bcx, C_disr(bcx.ccx(), discr), GEPi(bcx, val, [0, 0]))
}
Univariant(ref st, true) => {
assert_eq!(discr, 0);
@ -386,7 +386,7 @@ pub fn trans_start_init(bcx: @mut Block, r: &Repr, val: ValueRef, discr: Disr) {
assert_eq!(discr, 0);
}
General(*) => {
Store(bcx, C_uint(bcx.ccx(), discr/*bad*/ as uint), GEPi(bcx, val, [0, 0]))
Store(bcx, C_disr(bcx.ccx(), discr), GEPi(bcx, val, [0, 0]))
}
NullablePointer{ nonnull: ref nonnull, nndiscr, ptrfield, _ } => {
if discr != nndiscr {
@ -501,7 +501,7 @@ pub fn trans_const(ccx: &mut CrateContext, r: &Repr, discr: Disr,
CEnum(min, max) => {
assert_eq!(vals.len(), 0);
assert!(min <= discr && discr <= max);
C_uint(ccx, discr/*bad*/ as uint)
C_disr(ccx, discr)
}
Univariant(ref st, _dro) => {
assert_eq!(discr, 0);
@ -510,7 +510,7 @@ pub fn trans_const(ccx: &mut CrateContext, r: &Repr, discr: Disr,
General(ref cases) => {
let case = &cases[discr];
let max_sz = cases.iter().map(|x| x.size).max().unwrap();
let discr_ty = C_uint(ccx, discr/*bad*/ as uint);
let discr_ty = C_disr(ccx, discr);
let contents = build_const_struct(ccx, case,
~[discr_ty] + vals);
C_struct(contents + &[padding(max_sz - case.size)])
@ -645,3 +645,7 @@ pub fn is_newtypeish(r: &Repr) -> bool {
_ => false
}
}
fn C_disr(cx: &CrateContext, i: Disr) -> ValueRef {
return C_integral(cx.int_type, i, false);
}

View File

@ -453,7 +453,7 @@ fn const_expr_unadjusted(cx: @mut CrateContext, e: &ast::expr) -> ValueRef {
(expr::cast_enum, expr::cast_float) => {
let repr = adt::represent_type(cx, basety);
let discr = adt::const_get_discrim(cx, repr, v);
let iv = C_uint(cx, discr /*bad*/ as uint);
let iv = C_integral(cx.int_type, discr, false);
let ety_cast = expr::cast_type_kind(ety);
match ety_cast {
expr::cast_integral => {

View File

@ -317,7 +317,7 @@ impl Reflector {
for (i, v) in variants.iter().enumerate() {
let name = ccx.sess.str_of(v.name);
let variant_args = ~[this.c_uint(i),
this.c_uint(v.disr_val /*bad*/ as uint),
C_integral(self.bcx.ccx().int_type, v.disr_val, false),
this.c_uint(v.args.len()),
this.c_slice(name)];
do this.bracketed("enum_variant", variant_args) |this| {