summaryrefslogtreecommitdiffstats
path: root/tests/mir-opt/building/custom/as_cast.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:29 +0000
commit631cd5845e8de329d0e227aaa707d7ea228b8f8f (patch)
treea1b87c8f8cad01cf18f7c5f57a08f102771ed303 /tests/mir-opt/building/custom/as_cast.rs
parentAdding debian version 1.69.0+dfsg1-1. (diff)
downloadrustc-631cd5845e8de329d0e227aaa707d7ea228b8f8f.tar.xz
rustc-631cd5845e8de329d0e227aaa707d7ea228b8f8f.zip
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
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());
+}