Skip to content

Commit

Permalink
Calculate discriminant bounds within 64 bits
Browse files Browse the repository at this point in the history
Since discriminants do not support i128 yet, lets just calculate the boundaries within the 64 bits
that are supported. This also avoids an issue with bootstrapping on 32 bit systems due to #38727.
  • Loading branch information
nagisa committed Dec 31, 2016
1 parent 6b35963 commit ee69cd7
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
20 changes: 13 additions & 7 deletions src/librustc/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use ty::{self, Ty, TyCtxt, TypeFoldable};
use syntax::ast::{FloatTy, IntTy, UintTy};
use syntax::attr;
use syntax_pos::DUMMY_SP;
use rustc_i128::{i128, u128};
use rustc_i128::u128;
use rustc_const_math::ConstInt;

use std::cmp;
use std::fmt;
Expand Down Expand Up @@ -1198,20 +1199,25 @@ impl<'a, 'gcx, 'tcx> Layout {

if def.is_enum() && def.variants.iter().all(|v| v.fields.is_empty()) {
// All bodies empty -> intlike
let (mut min, mut max, mut non_zero) = (i128::max_value(),
i128::min_value(),
let (mut min, mut max, mut non_zero) = (i64::max_value(),
i64::min_value(),
true);
for v in &def.variants {
let x = v.disr_val.to_u128_unchecked() as i128;
let x = match v.disr_val.erase_type() {
ConstInt::InferSigned(i) => i as i64,
ConstInt::Infer(i) => i as u64 as i64,
_ => bug!()
};
if x == 0 { non_zero = false; }
if x < min { min = x; }
if x > max { max = x; }
}

// FIXME: should take i128?
// FIXME: should handle i128? signed-value based impl is weird and hard to
// grok.
let (discr, signed) = Integer::repr_discr(tcx, ty, &hints[..],
min as i64,
max as i64);
min,
max);
return success(CEnum {
discr: discr,
signed: signed,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub enum LLVMRustResult {
// Consts for the LLVM CallConv type, pre-cast to usize.

/// LLVM CallingConv::ID. Should we wrap this?
#[derive(Copy, Clone, PartialEq)]
#[derive(Copy, Clone, PartialEq, Debug)]
#[repr(C)]
pub enum CallConv {
CCallConv = 0,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ impl ArgType {
///
/// I will do my best to describe this structure, but these
/// comments are reverse-engineered and may be inaccurate. -NDM
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct FnType {
/// The LLVM types of each argument.
pub args: Vec<ArgType>,
Expand Down
1 change: 1 addition & 0 deletions src/librustc_trans/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ pub fn trans_mir<'a, 'tcx: 'a>(
sig: &ty::FnSig<'tcx>,
abi: Abi,
) {
debug!("fn_ty: {:?}", fn_ty);
let debug_context =
debuginfo::create_function_debug_context(fcx.ccx, instance, sig, abi, fcx.llfn, mir);
let bcx = fcx.get_entry_block();
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/mir/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl<'a, 'tcx> OperandRef<'tcx> {
pub fn immediate(self) -> ValueRef {
match self.val {
OperandValue::Immediate(s) => s,
_ => bug!()
_ => bug!("not immediate: {:?}", self)
}
}

Expand Down

0 comments on commit ee69cd7

Please sign in to comment.