Skip to content

Commit ee69cd7

Browse files
committed
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.
1 parent 6b35963 commit ee69cd7

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

src/librustc/ty/layout.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ use ty::{self, Ty, TyCtxt, TypeFoldable};
2020
use syntax::ast::{FloatTy, IntTy, UintTy};
2121
use syntax::attr;
2222
use syntax_pos::DUMMY_SP;
23-
use rustc_i128::{i128, u128};
23+
use rustc_i128::u128;
24+
use rustc_const_math::ConstInt;
2425

2526
use std::cmp;
2627
use std::fmt;
@@ -1198,20 +1199,25 @@ impl<'a, 'gcx, 'tcx> Layout {
11981199

11991200
if def.is_enum() && def.variants.iter().all(|v| v.fields.is_empty()) {
12001201
// All bodies empty -> intlike
1201-
let (mut min, mut max, mut non_zero) = (i128::max_value(),
1202-
i128::min_value(),
1202+
let (mut min, mut max, mut non_zero) = (i64::max_value(),
1203+
i64::min_value(),
12031204
true);
12041205
for v in &def.variants {
1205-
let x = v.disr_val.to_u128_unchecked() as i128;
1206+
let x = match v.disr_val.erase_type() {
1207+
ConstInt::InferSigned(i) => i as i64,
1208+
ConstInt::Infer(i) => i as u64 as i64,
1209+
_ => bug!()
1210+
};
12061211
if x == 0 { non_zero = false; }
12071212
if x < min { min = x; }
12081213
if x > max { max = x; }
12091214
}
12101215

1211-
// FIXME: should take i128?
1216+
// FIXME: should handle i128? signed-value based impl is weird and hard to
1217+
// grok.
12121218
let (discr, signed) = Integer::repr_discr(tcx, ty, &hints[..],
1213-
min as i64,
1214-
max as i64);
1219+
min,
1220+
max);
12151221
return success(CEnum {
12161222
discr: discr,
12171223
signed: signed,

src/librustc_llvm/ffi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub enum LLVMRustResult {
3333
// Consts for the LLVM CallConv type, pre-cast to usize.
3434

3535
/// LLVM CallingConv::ID. Should we wrap this?
36-
#[derive(Copy, Clone, PartialEq)]
36+
#[derive(Copy, Clone, PartialEq, Debug)]
3737
#[repr(C)]
3838
pub enum CallConv {
3939
CCallConv = 0,

src/librustc_trans/abi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ impl ArgType {
313313
///
314314
/// I will do my best to describe this structure, but these
315315
/// comments are reverse-engineered and may be inaccurate. -NDM
316-
#[derive(Clone)]
316+
#[derive(Clone, Debug)]
317317
pub struct FnType {
318318
/// The LLVM types of each argument.
319319
pub args: Vec<ArgType>,

src/librustc_trans/mir/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ pub fn trans_mir<'a, 'tcx: 'a>(
205205
sig: &ty::FnSig<'tcx>,
206206
abi: Abi,
207207
) {
208+
debug!("fn_ty: {:?}", fn_ty);
208209
let debug_context =
209210
debuginfo::create_function_debug_context(fcx.ccx, instance, sig, abi, fcx.llfn, mir);
210211
let bcx = fcx.get_entry_block();

src/librustc_trans/mir/operand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl<'a, 'tcx> OperandRef<'tcx> {
7979
pub fn immediate(self) -> ValueRef {
8080
match self.val {
8181
OperandValue::Immediate(s) => s,
82-
_ => bug!()
82+
_ => bug!("not immediate: {:?}", self)
8383
}
8484
}
8585

0 commit comments

Comments
 (0)