@@ -13,7 +13,7 @@ use rustc::middle::const_val::ConstVal;
13
13
use rustc_const_eval:: { ErrKind , ConstEvalErr , report_const_eval_err} ;
14
14
use rustc_const_math:: ConstInt :: * ;
15
15
use rustc_const_math:: ConstFloat :: * ;
16
- use rustc_const_math:: { ConstInt , ConstIsize , ConstUsize , ConstMathErr } ;
16
+ use rustc_const_math:: { ConstInt , ConstMathErr } ;
17
17
use rustc:: hir:: def_id:: DefId ;
18
18
use rustc:: infer:: TransNormalize ;
19
19
use rustc:: mir:: repr as mir;
@@ -28,14 +28,13 @@ use callee::Callee;
28
28
use common:: { self , BlockAndBuilder , CrateContext , const_get_elt, val_ty} ;
29
29
use common:: { C_array , C_bool , C_bytes , C_floating_f64 , C_integral , C_big_integral } ;
30
30
use common:: { C_null , C_struct , C_str_slice , C_undef , C_uint } ;
31
- use common:: { const_to_opt_int , const_to_opt_uint } ;
31
+ use common:: { const_to_opt_u128 } ;
32
32
use consts;
33
33
use monomorphize:: { self , Instance } ;
34
34
use type_of;
35
35
use type_:: Type ;
36
36
use value:: Value ;
37
37
38
- use syntax:: ast;
39
38
use syntax_pos:: { Span , DUMMY_SP } ;
40
39
use rustc_i128:: u128;
41
40
@@ -44,6 +43,8 @@ use std::ptr;
44
43
use super :: operand:: { OperandRef , OperandValue } ;
45
44
use super :: MirContext ;
46
45
46
+ use rustc_i128:: { i128} ;
47
+
47
48
/// A sized constant rvalue.
48
49
/// The LLVM type might not be the same for a single Rust type,
49
50
/// e.g. each enum variant would have its own LLVM struct type.
@@ -445,15 +446,15 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
445
446
mir:: ProjectionElem :: Index ( ref index) => {
446
447
let llindex = self . const_operand ( index, span) ?. llval ;
447
448
448
- let iv = if let Some ( iv) = common:: const_to_opt_uint ( llindex) {
449
+ let iv = if let Some ( iv) = common:: const_to_opt_u128 ( llindex, false ) {
449
450
iv
450
451
} else {
451
452
span_bug ! ( span, "index is not an integer-constant expression" )
452
453
} ;
453
454
454
455
// Produce an undef instead of a LLVM assertion on OOB.
455
456
let len = common:: const_to_uint ( tr_base. len ( self . ccx ) ) ;
456
- let llelem = if iv < len {
457
+ let llelem = if iv < len as u128 {
457
458
const_get_elt ( base. llval , & [ iv as u32 ] )
458
459
} else {
459
460
C_undef ( type_of:: type_of ( self . ccx , projected_ty) )
@@ -796,49 +797,14 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
796
797
797
798
fn to_const_int ( value : ValueRef , t : Ty , tcx : TyCtxt ) -> Option < ConstInt > {
798
799
match t. sty {
799
- ty:: TyInt ( int_type) => const_to_opt_int ( value) . and_then ( |input| match int_type {
800
- ast:: IntTy :: I8 => {
801
- assert_eq ! ( input as i8 as i64 , input) ;
802
- Some ( ConstInt :: I8 ( input as i8 ) )
803
- } ,
804
- ast:: IntTy :: I16 => {
805
- assert_eq ! ( input as i16 as i64 , input) ;
806
- Some ( ConstInt :: I16 ( input as i16 ) )
807
- } ,
808
- ast:: IntTy :: I32 => {
809
- assert_eq ! ( input as i32 as i64 , input) ;
810
- Some ( ConstInt :: I32 ( input as i32 ) )
811
- } ,
812
- ast:: IntTy :: I64 => {
813
- Some ( ConstInt :: I64 ( input) )
814
- } ,
815
- ast:: IntTy :: Is => {
816
- ConstIsize :: new ( input, tcx. sess . target . int_type )
817
- . ok ( ) . map ( ConstInt :: Isize )
818
- } ,
819
- } ) ,
820
- ty:: TyUint ( uint_type) => const_to_opt_uint ( value) . and_then ( |input| match uint_type {
821
- ast:: UintTy :: U8 => {
822
- assert_eq ! ( input as u8 as u64 , input) ;
823
- Some ( ConstInt :: U8 ( input as u8 ) )
824
- } ,
825
- ast:: UintTy :: U16 => {
826
- assert_eq ! ( input as u16 as u64 , input) ;
827
- Some ( ConstInt :: U16 ( input as u16 ) )
828
- } ,
829
- ast:: UintTy :: U32 => {
830
- assert_eq ! ( input as u32 as u64 , input) ;
831
- Some ( ConstInt :: U32 ( input as u32 ) )
832
- } ,
833
- ast:: UintTy :: U64 => {
834
- Some ( ConstInt :: U64 ( input) )
835
- } ,
836
- ast:: UintTy :: Us => {
837
- ConstUsize :: new ( input, tcx. sess . target . uint_type )
838
- . ok ( ) . map ( ConstInt :: Usize )
839
- } ,
840
- } ) ,
841
- _ => None ,
800
+ ty:: TyInt ( int_type) => const_to_opt_u128 ( value, true )
801
+ . and_then ( |input| ConstInt :: new_signed ( input as i128 , int_type,
802
+ tcx. sess . target . int_type ) ) ,
803
+ ty:: TyUint ( uint_type) => const_to_opt_u128 ( value, false )
804
+ . and_then ( |input| ConstInt :: new_unsigned ( input, uint_type,
805
+ tcx. sess . target . uint_type ) ) ,
806
+ _ => None
807
+
842
808
}
843
809
}
844
810
0 commit comments