summaryrefslogtreecommitdiffstats
path: root/tests/mir-opt/building/custom/as_cast.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/mir-opt/building/custom/as_cast.rs')
-rw-r--r--tests/mir-opt/building/custom/as_cast.rs43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/mir-opt/building/custom/as_cast.rs b/tests/mir-opt/building/custom/as_cast.rs
new file mode 100644
index 000000000..b4b5ac6aa
--- /dev/null
+++ b/tests/mir-opt/building/custom/as_cast.rs
@@ -0,0 +1,43 @@
+#![feature(custom_mir, core_intrinsics)]
+
+extern crate core;
+use core::intrinsics::mir::*;
+
+// EMIT_MIR as_cast.int_to_int.built.after.mir
+#[custom_mir(dialect = "built")]
+fn int_to_int(x: u32) -> i32 {
+ mir!(
+ {
+ RET = x as i32;
+ Return()
+ }
+ )
+}
+
+// EMIT_MIR as_cast.float_to_int.built.after.mir
+#[custom_mir(dialect = "built")]
+fn float_to_int(x: f32) -> i32 {
+ mir!(
+ {
+ RET = x as i32;
+ Return()
+ }
+ )
+}
+
+// EMIT_MIR as_cast.int_to_ptr.built.after.mir
+#[custom_mir(dialect = "built")]
+fn int_to_ptr(x: usize) -> *const i32 {
+ mir!(
+ {
+ RET = x as *const i32;
+ Return()
+ }
+ )
+}
+
+fn main() {
+ assert_eq!(int_to_int(5), 5);
+ assert_eq!(float_to_int(5.), 5);
+ assert_eq!(int_to_ptr(0), std::ptr::null());
+}