about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-06-10 19:50:42 -0700
committerGitHub <noreply@github.com>2016-06-10 19:50:42 -0700
commitf80ff7da394da0be629df6758b8fd513ee6ef438 (patch)
tree4bab96ba89dd04d81061b9112854692fdfa88032
parent0554abac637800415bb1b30d8656898552a55ea0 (diff)
parent1858cfb80d865f733aba16e679b842365f5ae4cd (diff)
downloadrust-f80ff7da394da0be629df6758b8fd513ee6ef438.tar.gz
rust-f80ff7da394da0be629df6758b8fd513ee6ef438.zip
Auto merge of #34174 - shepmaster:16-bit-mir, r=Aatch
Support 16-bit pointers in MIR
-rw-r--r--src/librustc_const_eval/eval.rs25
-rw-r--r--src/librustc_const_math/is.rs11
-rw-r--r--src/librustc_const_math/us.rs11
-rw-r--r--src/librustc_mir/build/expr/as_rvalue.rs1
4 files changed, 26 insertions, 22 deletions
diff --git a/src/librustc_const_eval/eval.rs b/src/librustc_const_eval/eval.rs
index c3db252584c..7551bc5c234 100644
--- a/src/librustc_const_eval/eval.rs
+++ b/src/librustc_const_eval/eval.rs
@@ -945,10 +945,7 @@ fn infer<'a, 'tcx>(i: ConstInt,
         (&ty::TyInt(IntTy::I32), Infer(i)) => Ok(I32(i as i64 as i32)),
         (&ty::TyInt(IntTy::I64), Infer(i)) => Ok(I64(i as i64)),
         (&ty::TyInt(IntTy::Is), Infer(i)) => {
-            match ConstIsize::new(i as i64, tcx.sess.target.int_type) {
-                Ok(val) => Ok(Isize(val)),
-                Err(_) => Ok(Isize(ConstIsize::Is32(i as i64 as i32))),
-            }
+            Ok(Isize(ConstIsize::new_truncating(i as i64, tcx.sess.target.int_type)))
         },
 
         (&ty::TyInt(IntTy::I8), InferSigned(i)) => Ok(I8(i as i8)),
@@ -956,10 +953,7 @@ fn infer<'a, 'tcx>(i: ConstInt,
         (&ty::TyInt(IntTy::I32), InferSigned(i)) => Ok(I32(i as i32)),
         (&ty::TyInt(IntTy::I64), InferSigned(i)) => Ok(I64(i)),
         (&ty::TyInt(IntTy::Is), InferSigned(i)) => {
-            match ConstIsize::new(i, tcx.sess.target.int_type) {
-                Ok(val) => Ok(Isize(val)),
-                Err(_) => Ok(Isize(ConstIsize::Is32(i as i32))),
-            }
+            Ok(Isize(ConstIsize::new_truncating(i, tcx.sess.target.int_type)))
         },
 
         (&ty::TyUint(UintTy::U8), Infer(i)) => Ok(U8(i as u8)),
@@ -967,10 +961,7 @@ fn infer<'a, 'tcx>(i: ConstInt,
         (&ty::TyUint(UintTy::U32), Infer(i)) => Ok(U32(i as u32)),
         (&ty::TyUint(UintTy::U64), Infer(i)) => Ok(U64(i)),
         (&ty::TyUint(UintTy::Us), Infer(i)) => {
-            match ConstUsize::new(i, tcx.sess.target.uint_type) {
-                Ok(val) => Ok(Usize(val)),
-                Err(_) => Ok(Usize(ConstUsize::Us32(i as u32))),
-            }
+            Ok(Usize(ConstUsize::new_truncating(i, tcx.sess.target.uint_type)))
         },
         (&ty::TyUint(_), InferSigned(_)) => Err(IntermediateUnsignedNegative),
 
@@ -1052,20 +1043,14 @@ fn cast_const_int<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, val: ConstInt, ty: ty::
         ty::TyInt(ast::IntTy::I32) => Ok(Integral(I32(v as i64 as i32))),
         ty::TyInt(ast::IntTy::I64) => Ok(Integral(I64(v as i64))),
         ty::TyInt(ast::IntTy::Is) => {
-            match ConstIsize::new(v as i64, tcx.sess.target.int_type) {
-                Ok(val) => Ok(Integral(Isize(val))),
-                Err(_) => Ok(Integral(Isize(ConstIsize::Is32(v as i64 as i32)))),
-            }
+            Ok(Integral(Isize(ConstIsize::new_truncating(v as i64, tcx.sess.target.int_type))))
         },
         ty::TyUint(ast::UintTy::U8) => Ok(Integral(U8(v as u8))),
         ty::TyUint(ast::UintTy::U16) => Ok(Integral(U16(v as u16))),
         ty::TyUint(ast::UintTy::U32) => Ok(Integral(U32(v as u32))),
         ty::TyUint(ast::UintTy::U64) => Ok(Integral(U64(v))),
         ty::TyUint(ast::UintTy::Us) => {
-            match ConstUsize::new(v, tcx.sess.target.uint_type) {
-                Ok(val) => Ok(Integral(Usize(val))),
-                Err(_) => Ok(Integral(Usize(ConstUsize::Us32(v as u32)))),
-            }
+            Ok(Integral(Usize(ConstUsize::new_truncating(v, tcx.sess.target.uint_type))))
         },
         ty::TyFloat(ast::FloatTy::F64) => match val.erase_type() {
             Infer(u) => Ok(Float(F64(u as f64))),
diff --git a/src/librustc_const_math/is.rs b/src/librustc_const_math/is.rs
index 4d2db355eb0..ef92b628523 100644
--- a/src/librustc_const_math/is.rs
+++ b/src/librustc_const_math/is.rs
@@ -27,7 +27,8 @@ impl ConstIsize {
             (Is16(i), ast::IntTy::I16) => i as i64,
             (Is32(i), ast::IntTy::I32) => i as i64,
             (Is64(i), ast::IntTy::I64) => i,
-            _ => panic!("got invalid isize size for target"),
+            _ => panic!("unable to convert self ({:?}) to target isize ({:?})",
+                        self, target_int_ty),
         }
     }
     pub fn new(i: i64, target_int_ty: ast::IntTy) -> Result<Self, ConstMathErr> {
@@ -40,4 +41,12 @@ impl ConstIsize {
             _ => unreachable!(),
         }
     }
+    pub fn new_truncating(i: i64, target_int_ty: ast::IntTy) -> Self {
+        match target_int_ty {
+            ast::IntTy::I16 => Is16(i as i16),
+            ast::IntTy::I32 => Is32(i as i32),
+            ast::IntTy::I64 => Is64(i),
+            _ => unreachable!(),
+        }
+    }
 }
diff --git a/src/librustc_const_math/us.rs b/src/librustc_const_math/us.rs
index 2b224d06466..bf73ff03c98 100644
--- a/src/librustc_const_math/us.rs
+++ b/src/librustc_const_math/us.rs
@@ -27,7 +27,8 @@ impl ConstUsize {
             (Us16(i), ast::UintTy::U16) => i as u64,
             (Us32(i), ast::UintTy::U32) => i as u64,
             (Us64(i), ast::UintTy::U64) => i,
-            _ => panic!("got invalid usize size for target"),
+            _ => panic!("unable to convert self ({:?}) to target usize ({:?})",
+                        self, target_uint_ty),
         }
     }
     pub fn new(i: u64, target_uint_ty: ast::UintTy) -> Result<Self, ConstMathErr> {
@@ -40,4 +41,12 @@ impl ConstUsize {
             _ => unreachable!(),
         }
     }
+    pub fn new_truncating(i: u64, target_uint_ty: ast::UintTy) -> Self {
+        match target_uint_ty {
+            ast::UintTy::U16 => Us16(i as u16),
+            ast::UintTy::U32 => Us32(i as u32),
+            ast::UintTy::U64 => Us64(i),
+            _ => unreachable!(),
+        }
+    }
 }
diff --git a/src/librustc_mir/build/expr/as_rvalue.rs b/src/librustc_mir/build/expr/as_rvalue.rs
index c0c27ac5943..ab7bc4eec91 100644
--- a/src/librustc_mir/build/expr/as_rvalue.rs
+++ b/src/librustc_mir/build/expr/as_rvalue.rs
@@ -368,6 +368,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
                     ast::IntTy::Is => {
                         let int_ty = self.hir.tcx().sess.target.int_type;
                         let min = match int_ty {
+                            ast::IntTy::I16 => std::i16::MIN as i64,
                             ast::IntTy::I32 => std::i32::MIN as i64,
                             ast::IntTy::I64 => std::i64::MIN,
                             _ => unreachable!()