提交 ee69cd79 编写于 作者: S Simonas Kazlauskas

Calculate discriminant bounds within 64 bits

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.
上级 6b359635
......@@ -20,7 +20,8 @@
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;
......@@ -1198,20 +1199,25 @@ pub fn compute_uncached(ty: Ty<'gcx>,
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,
......
......@@ -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,
......
......@@ -313,7 +313,7 @@ pub fn store_fn_arg(&self, bcx: &BlockAndBuilder, idx: &mut usize, dst: ValueRef
///
/// 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>,
......
......@@ -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();
......
......@@ -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)
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册