@@ -13,7 +13,7 @@ use rustc::middle::const_val::ConstVal;
1313use rustc_const_eval:: { ErrKind , ConstEvalErr , report_const_eval_err} ;
1414use rustc_const_math:: ConstInt :: * ;
1515use rustc_const_math:: ConstFloat :: * ;
16- use rustc_const_math:: { ConstInt , ConstIsize , ConstUsize , ConstMathErr } ;
16+ use rustc_const_math:: { ConstInt , ConstMathErr } ;
1717use rustc:: hir:: def_id:: DefId ;
1818use rustc:: infer:: TransNormalize ;
1919use rustc:: mir:: repr as mir;
@@ -28,14 +28,13 @@ use callee::Callee;
2828use common:: { self , BlockAndBuilder , CrateContext , const_get_elt, val_ty} ;
2929use common:: { C_array , C_bool , C_bytes , C_floating_f64 , C_integral , C_big_integral } ;
3030use 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 } ;
3232use consts;
3333use monomorphize:: { self , Instance } ;
3434use type_of;
3535use type_:: Type ;
3636use value:: Value ;
3737
38- use syntax:: ast;
3938use syntax_pos:: { Span , DUMMY_SP } ;
4039use rustc_i128:: u128;
4140
@@ -44,6 +43,8 @@ use std::ptr;
4443use super :: operand:: { OperandRef , OperandValue } ;
4544use super :: MirContext ;
4645
46+ use rustc_i128:: { i128} ;
47+
4748/// A sized constant rvalue.
4849/// The LLVM type might not be the same for a single Rust type,
4950/// e.g. each enum variant would have its own LLVM struct type.
@@ -445,15 +446,15 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
445446 mir:: ProjectionElem :: Index ( ref index) => {
446447 let llindex = self . const_operand ( index, span) ?. llval ;
447448
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 ) {
449450 iv
450451 } else {
451452 span_bug ! ( span, "index is not an integer-constant expression" )
452453 } ;
453454
454455 // Produce an undef instead of a LLVM assertion on OOB.
455456 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 {
457458 const_get_elt ( base. llval , & [ iv as u32 ] )
458459 } else {
459460 C_undef ( type_of:: type_of ( self . ccx , projected_ty) )
@@ -796,49 +797,14 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
796797
797798fn to_const_int ( value : ValueRef , t : Ty , tcx : TyCtxt ) -> Option < ConstInt > {
798799 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+
842808 }
843809}
844810
0 commit comments