summaryrefslogtreecommitdiffstats
path: root/tests/mir-opt/building/custom
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:39 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:39 +0000
commit1376c5a617be5c25655d0d7cb63e3beaa5a6e026 (patch)
tree3bb8d61aee02bc7a15eab3f36e3b921afc2075d0 /tests/mir-opt/building/custom
parentReleasing progress-linux version 1.69.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.tar.xz
rustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.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')
-rw-r--r--tests/mir-opt/building/custom/aggregate_exprs.adt.built.after.mir16
-rw-r--r--tests/mir-opt/building/custom/aggregate_exprs.array.built.after.mir15
-rw-r--r--tests/mir-opt/building/custom/aggregate_exprs.rs71
-rw-r--r--tests/mir-opt/building/custom/aggregate_exprs.tuple.built.after.mir10
-rw-r--r--tests/mir-opt/building/custom/as_cast.float_to_int.built.after.mir10
-rw-r--r--tests/mir-opt/building/custom/as_cast.int_to_int.built.after.mir10
-rw-r--r--tests/mir-opt/building/custom/as_cast.int_to_ptr.built.after.mir10
-rw-r--r--tests/mir-opt/building/custom/as_cast.rs43
-rw-r--r--tests/mir-opt/building/custom/composite_return.rs21
-rw-r--r--tests/mir-opt/building/custom/composite_return.tuple.built.after.mir11
-rw-r--r--tests/mir-opt/building/custom/references.raw_pointer_offset.built.after.mir10
-rw-r--r--tests/mir-opt/building/custom/references.rs11
-rw-r--r--tests/mir-opt/building/custom/terminators.drop_first.built.after.mir5
-rw-r--r--tests/mir-opt/building/custom/terminators.rs3
14 files changed, 243 insertions, 3 deletions
diff --git a/tests/mir-opt/building/custom/aggregate_exprs.adt.built.after.mir b/tests/mir-opt/building/custom/aggregate_exprs.adt.built.after.mir
new file mode 100644
index 000000000..49e8c812c
--- /dev/null
+++ b/tests/mir-opt/building/custom/aggregate_exprs.adt.built.after.mir
@@ -0,0 +1,16 @@
+// MIR for `adt` after built
+
+fn adt() -> Onion {
+ let mut _0: Onion; // return place in scope 0 at $DIR/aggregate_exprs.rs:+0:13: +0:18
+ let mut _1: i32; // in scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL
+ let mut _2: Foo; // in scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL
+ let mut _3: Bar; // in scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL
+
+ bb0: {
+ _1 = const 1_i32; // scope 0 at $DIR/aggregate_exprs.rs:+6:13: +6:20
+ _2 = Foo { a: const 1_i32, b: const 2_i32 }; // scope 0 at $DIR/aggregate_exprs.rs:+7:13: +10:14
+ _3 = Bar::Foo(move _2, _1); // scope 0 at $DIR/aggregate_exprs.rs:+11:13: +11:39
+ _0 = Onion { neon: ((_3 as variant#0).1: i32) }; // scope 0 at $DIR/aggregate_exprs.rs:+12:13: +12:58
+ return; // scope 0 at $DIR/aggregate_exprs.rs:+13:13: +13:21
+ }
+}
diff --git a/tests/mir-opt/building/custom/aggregate_exprs.array.built.after.mir b/tests/mir-opt/building/custom/aggregate_exprs.array.built.after.mir
new file mode 100644
index 000000000..30d128973
--- /dev/null
+++ b/tests/mir-opt/building/custom/aggregate_exprs.array.built.after.mir
@@ -0,0 +1,15 @@
+// MIR for `array` after built
+
+fn array() -> [i32; 2] {
+ let mut _0: [i32; 2]; // return place in scope 0 at $DIR/aggregate_exprs.rs:+0:15: +0:23
+ let mut _1: [i32; 2]; // in scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL
+ let mut _2: i32; // in scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL
+
+ bb0: {
+ _1 = [const 42_i32, const 43_i32]; // scope 0 at $DIR/aggregate_exprs.rs:+5:13: +5:25
+ _2 = const 1_i32; // scope 0 at $DIR/aggregate_exprs.rs:+6:13: +6:20
+ _1 = [_2, const 2_i32]; // scope 0 at $DIR/aggregate_exprs.rs:+7:13: +7:25
+ _0 = move _1; // scope 0 at $DIR/aggregate_exprs.rs:+8:13: +8:26
+ return; // scope 0 at $DIR/aggregate_exprs.rs:+9:13: +9:21
+ }
+}
diff --git a/tests/mir-opt/building/custom/aggregate_exprs.rs b/tests/mir-opt/building/custom/aggregate_exprs.rs
new file mode 100644
index 000000000..554c9c03b
--- /dev/null
+++ b/tests/mir-opt/building/custom/aggregate_exprs.rs
@@ -0,0 +1,71 @@
+#![feature(custom_mir, core_intrinsics)]
+
+extern crate core;
+use core::intrinsics::mir::*;
+
+// EMIT_MIR aggregate_exprs.tuple.built.after.mir
+#[custom_mir(dialect = "built")]
+fn tuple() -> (i32, bool) {
+ mir!(
+ {
+ RET = (1, true);
+ Return()
+ }
+ )
+}
+
+// EMIT_MIR aggregate_exprs.array.built.after.mir
+#[custom_mir(dialect = "built")]
+fn array() -> [i32; 2] {
+ mir!(
+ let x: [i32; 2];
+ let one: i32;
+ {
+ x = [42, 43];
+ one = 1;
+ x = [one, 2];
+ RET = Move(x);
+ Return()
+ }
+ )
+}
+
+struct Foo {
+ a: i32,
+ b: i32,
+}
+
+enum Bar {
+ Foo(Foo, i32),
+}
+
+union Onion {
+ neon: i32,
+ noun: f32,
+}
+
+// EMIT_MIR aggregate_exprs.adt.built.after.mir
+#[custom_mir(dialect = "built")]
+fn adt() -> Onion {
+ mir!(
+ let one: i32;
+ let x: Foo;
+ let y: Bar;
+ {
+ one = 1;
+ x = Foo {
+ a: 1,
+ b: 2,
+ };
+ y = Bar::Foo(Move(x), one);
+ RET = Onion { neon: Field(Variant(y, 0), 1) };
+ Return()
+ }
+ )
+}
+
+fn main() {
+ assert_eq!(tuple(), (1, true));
+ assert_eq!(array(), [1, 2]);
+ assert_eq!(unsafe { adt().neon }, 1);
+}
diff --git a/tests/mir-opt/building/custom/aggregate_exprs.tuple.built.after.mir b/tests/mir-opt/building/custom/aggregate_exprs.tuple.built.after.mir
new file mode 100644
index 000000000..5fe45ccc9
--- /dev/null
+++ b/tests/mir-opt/building/custom/aggregate_exprs.tuple.built.after.mir
@@ -0,0 +1,10 @@
+// MIR for `tuple` after built
+
+fn tuple() -> (i32, bool) {
+ let mut _0: (i32, bool); // return place in scope 0 at $DIR/aggregate_exprs.rs:+0:15: +0:26
+
+ bb0: {
+ _0 = (const 1_i32, const true); // scope 0 at $DIR/aggregate_exprs.rs:+3:13: +3:28
+ return; // scope 0 at $DIR/aggregate_exprs.rs:+4:13: +4:21
+ }
+}
diff --git a/tests/mir-opt/building/custom/as_cast.float_to_int.built.after.mir b/tests/mir-opt/building/custom/as_cast.float_to_int.built.after.mir
new file mode 100644
index 000000000..d0b770783
--- /dev/null
+++ b/tests/mir-opt/building/custom/as_cast.float_to_int.built.after.mir
@@ -0,0 +1,10 @@
+// MIR for `float_to_int` after built
+
+fn float_to_int(_1: f32) -> i32 {
+ let mut _0: i32; // return place in scope 0 at $DIR/as_cast.rs:+0:28: +0:31
+
+ bb0: {
+ _0 = _1 as i32 (FloatToInt); // scope 0 at $DIR/as_cast.rs:+3:13: +3:27
+ return; // scope 0 at $DIR/as_cast.rs:+4:13: +4:21
+ }
+}
diff --git a/tests/mir-opt/building/custom/as_cast.int_to_int.built.after.mir b/tests/mir-opt/building/custom/as_cast.int_to_int.built.after.mir
new file mode 100644
index 000000000..aaebff0d7
--- /dev/null
+++ b/tests/mir-opt/building/custom/as_cast.int_to_int.built.after.mir
@@ -0,0 +1,10 @@
+// MIR for `int_to_int` after built
+
+fn int_to_int(_1: u32) -> i32 {
+ let mut _0: i32; // return place in scope 0 at $DIR/as_cast.rs:+0:26: +0:29
+
+ bb0: {
+ _0 = _1 as i32 (IntToInt); // scope 0 at $DIR/as_cast.rs:+3:13: +3:27
+ return; // scope 0 at $DIR/as_cast.rs:+4:13: +4:21
+ }
+}
diff --git a/tests/mir-opt/building/custom/as_cast.int_to_ptr.built.after.mir b/tests/mir-opt/building/custom/as_cast.int_to_ptr.built.after.mir
new file mode 100644
index 000000000..f040cf53d
--- /dev/null
+++ b/tests/mir-opt/building/custom/as_cast.int_to_ptr.built.after.mir
@@ -0,0 +1,10 @@
+// MIR for `int_to_ptr` after built
+
+fn int_to_ptr(_1: usize) -> *const i32 {
+ let mut _0: *const i32; // return place in scope 0 at $DIR/as_cast.rs:+0:28: +0:38
+
+ bb0: {
+ _0 = _1 as *const i32 (PointerFromExposedAddress); // scope 0 at $DIR/as_cast.rs:+3:13: +3:34
+ return; // scope 0 at $DIR/as_cast.rs:+4:13: +4:21
+ }
+}
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());
+}
diff --git a/tests/mir-opt/building/custom/composite_return.rs b/tests/mir-opt/building/custom/composite_return.rs
new file mode 100644
index 000000000..701d6b1ab
--- /dev/null
+++ b/tests/mir-opt/building/custom/composite_return.rs
@@ -0,0 +1,21 @@
+#![feature(custom_mir, core_intrinsics)]
+
+extern crate core;
+use core::intrinsics::mir::*;
+
+// EMIT_MIR composite_return.tuple.built.after.mir
+#[custom_mir(dialect = "runtime", phase = "optimized")]
+fn tuple() -> (i32, bool) {
+ mir!(
+ type RET = (i32, bool);
+ {
+ RET.0 = 1;
+ RET.1 = true;
+ Return()
+ }
+ )
+}
+
+fn main() {
+ assert_eq!(tuple(), (1, true));
+}
diff --git a/tests/mir-opt/building/custom/composite_return.tuple.built.after.mir b/tests/mir-opt/building/custom/composite_return.tuple.built.after.mir
new file mode 100644
index 000000000..d159c1a65
--- /dev/null
+++ b/tests/mir-opt/building/custom/composite_return.tuple.built.after.mir
@@ -0,0 +1,11 @@
+// MIR for `tuple` after built
+
+fn tuple() -> (i32, bool) {
+ let mut _0: (i32, bool); // return place in scope 0 at $DIR/composite_return.rs:+0:15: +0:26
+
+ bb0: {
+ (_0.0: i32) = const 1_i32; // scope 0 at $DIR/composite_return.rs:+4:13: +4:22
+ (_0.1: bool) = const true; // scope 0 at $DIR/composite_return.rs:+5:13: +5:25
+ return; // scope 0 at $DIR/composite_return.rs:+6:13: +6:21
+ }
+}
diff --git a/tests/mir-opt/building/custom/references.raw_pointer_offset.built.after.mir b/tests/mir-opt/building/custom/references.raw_pointer_offset.built.after.mir
new file mode 100644
index 000000000..f614aef40
--- /dev/null
+++ b/tests/mir-opt/building/custom/references.raw_pointer_offset.built.after.mir
@@ -0,0 +1,10 @@
+// MIR for `raw_pointer_offset` after built
+
+fn raw_pointer_offset(_1: *const i32) -> *const i32 {
+ let mut _0: *const i32; // return place in scope 0 at $DIR/references.rs:+0:45: +0:55
+
+ bb0: {
+ _0 = Offset(_1, const 1_isize); // scope 0 at $DIR/references.rs:+2:9: +2:33
+ return; // scope 0 at $DIR/references.rs:+3:9: +3:17
+ }
+}
diff --git a/tests/mir-opt/building/custom/references.rs b/tests/mir-opt/building/custom/references.rs
index a1c896de0..f87f6664c 100644
--- a/tests/mir-opt/building/custom/references.rs
+++ b/tests/mir-opt/building/custom/references.rs
@@ -45,11 +45,22 @@ pub fn raw_pointer(x: *const i32) -> *const i32 {
})
}
+// EMIT_MIR references.raw_pointer_offset.built.after.mir
+#[custom_mir(dialect = "built")]
+pub fn raw_pointer_offset(x: *const i32) -> *const i32 {
+ mir!({
+ RET = Offset(x, 1_isize);
+ Return()
+ })
+}
+
fn main() {
let mut x = 5;
+ let arr = [1, 2];
assert_eq!(*mut_ref(&mut x), 5);
assert_eq!(*immut_ref(&x), 5);
unsafe {
assert_eq!(*raw_pointer(addr_of!(x)), 5);
+ assert_eq!(*raw_pointer_offset(addr_of!(arr[0])), 2);
}
}
diff --git a/tests/mir-opt/building/custom/terminators.drop_first.built.after.mir b/tests/mir-opt/building/custom/terminators.drop_first.built.after.mir
index c903e5946..ada78c0fc 100644
--- a/tests/mir-opt/building/custom/terminators.drop_first.built.after.mir
+++ b/tests/mir-opt/building/custom/terminators.drop_first.built.after.mir
@@ -4,10 +4,11 @@ fn drop_first(_1: WriteOnDrop<'_>, _2: WriteOnDrop<'_>) -> () {
let mut _0: (); // return place in scope 0 at $DIR/terminators.rs:+0:59: +0:59
bb0: {
- replace(_1 <- move _2) -> bb1; // scope 0 at $DIR/terminators.rs:+3:13: +3:49
+ drop(_1) -> bb1; // scope 0 at $DIR/terminators.rs:+3:13: +3:30
}
bb1: {
- return; // scope 0 at $DIR/terminators.rs:+7:13: +7:21
+ _1 = move _2; // scope 0 at $DIR/terminators.rs:+7:13: +7:24
+ return; // scope 0 at $DIR/terminators.rs:+8:13: +8:21
}
}
diff --git a/tests/mir-opt/building/custom/terminators.rs b/tests/mir-opt/building/custom/terminators.rs
index c23233fcf..f12405661 100644
--- a/tests/mir-opt/building/custom/terminators.rs
+++ b/tests/mir-opt/building/custom/terminators.rs
@@ -48,10 +48,11 @@ impl<'a> Drop for WriteOnDrop<'a> {
fn drop_first<'a>(a: WriteOnDrop<'a>, b: WriteOnDrop<'a>) {
mir!(
{
- DropAndReplace(a, Move(b), retblock)
+ Drop(a, retblock)
}
retblock = {
+ a = Move(b);
Return()
}
)