Accommodate simple cases of arith-overflow in rustc
related crates.
This commit is contained in:
parent
f0404c39f2
commit
faf3bcd72c
@ -778,7 +778,9 @@ fn load_discr(bcx: Block, ity: IntType, ptr: ValueRef, min: Disr, max: Disr)
|
||||
assert!(bits <= 64);
|
||||
let bits = bits as uint;
|
||||
let mask = (-1u64 >> (64 - bits)) as Disr;
|
||||
if (max + 1) & mask == min & mask {
|
||||
// For a (max) discr of -1, max will be `-1 as usize`, which overflows.
|
||||
// However, that is fine here (it would still represent the full range),
|
||||
if (max.wrapping_add(1)) & mask == min & mask {
|
||||
// i.e., if the range is everything. The lo==hi case would be
|
||||
// rejected by the LLVM verifier (it would mean either an
|
||||
// empty set, which is impossible, or the entire range of the
|
||||
@ -787,7 +789,7 @@ fn load_discr(bcx: Block, ity: IntType, ptr: ValueRef, min: Disr, max: Disr)
|
||||
} else {
|
||||
// llvm::ConstantRange can deal with ranges that wrap around,
|
||||
// so an overflow on (max + 1) is fine.
|
||||
LoadRangeAssert(bcx, ptr, min, (max+1), /* signed: */ True)
|
||||
LoadRangeAssert(bcx, ptr, min, (max.wrapping_add(1)), /* signed: */ True)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -205,9 +205,9 @@ pub fn opt_ast_region_to_region<'tcx>(
|
||||
|
||||
if len == 2 && i == 0 {
|
||||
m.push_str(" or ");
|
||||
} else if i == len - 2 {
|
||||
} else if i + 2 == len {
|
||||
m.push_str(", or ");
|
||||
} else if i != len - 1 {
|
||||
} else if i + 1 != len {
|
||||
m.push_str(", ");
|
||||
}
|
||||
}
|
||||
|
@ -181,7 +181,6 @@ fn encodable_substructure(cx: &mut ExtCtxt, trait_span: Span,
|
||||
Struct(ref fields) => {
|
||||
let emit_struct_field = cx.ident_of("emit_struct_field");
|
||||
let mut stmts = Vec::new();
|
||||
let last = fields.len() - 1;
|
||||
for (i, &FieldInfo {
|
||||
name,
|
||||
ref self_,
|
||||
@ -204,6 +203,7 @@ fn encodable_substructure(cx: &mut ExtCtxt, trait_span: Span,
|
||||
lambda));
|
||||
|
||||
// last call doesn't need a try!
|
||||
let last = fields.len() - 1;
|
||||
let call = if i != last {
|
||||
cx.expr_try(span, call)
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user