summaryrefslogtreecommitdiffstats
path: root/src/test/run-make/const_fn_mir
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/run-make/const_fn_mir
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/run-make/const_fn_mir')
-rw-r--r--src/test/run-make/const_fn_mir/Makefile10
-rw-r--r--src/test/run-make/const_fn_mir/dump.mir42
-rw-r--r--src/test/run-make/const_fn_mir/main.rs10
3 files changed, 62 insertions, 0 deletions
diff --git a/src/test/run-make/const_fn_mir/Makefile b/src/test/run-make/const_fn_mir/Makefile
new file mode 100644
index 000000000..2aa0bc9d4
--- /dev/null
+++ b/src/test/run-make/const_fn_mir/Makefile
@@ -0,0 +1,10 @@
+-include ../../run-make-fulldeps/tools.mk
+
+all:
+ $(RUSTC) main.rs --emit=mir -o "$(TMPDIR)"/dump.mir
+
+ifdef RUSTC_BLESS_TEST
+ cp "$(TMPDIR)"/dump.mir dump.mir
+else
+ $(DIFF) dump.mir "$(TMPDIR)"/dump.mir
+endif
diff --git a/src/test/run-make/const_fn_mir/dump.mir b/src/test/run-make/const_fn_mir/dump.mir
new file mode 100644
index 000000000..ab4084c95
--- /dev/null
+++ b/src/test/run-make/const_fn_mir/dump.mir
@@ -0,0 +1,42 @@
+// WARNING: This output format is intended for human consumers only
+// and is subject to change without notice. Knock yourself out.
+fn foo() -> i32 {
+ let mut _0: i32; // return place in scope 0 at main.rs:4:19: 4:22
+
+ bb0: {
+ _0 = const 11_i32; // scope 0 at main.rs:5:5: 5:10
+ return; // scope 0 at main.rs:6:2: 6:2
+ }
+}
+
+// MIR FOR CTFE
+fn foo() -> i32 {
+ let mut _0: i32; // return place in scope 0 at main.rs:4:19: 4:22
+ let mut _1: (i32, bool); // in scope 0 at main.rs:5:5: 5:10
+
+ bb0: {
+ _1 = CheckedAdd(const 5_i32, const 6_i32); // scope 0 at main.rs:5:5: 5:10
+ assert(!move (_1.1: bool), "attempt to compute `{} + {}`, which would overflow", const 5_i32, const 6_i32) -> bb1; // scope 0 at main.rs:5:5: 5:10
+ }
+
+ bb1: {
+ _0 = move (_1.0: i32); // scope 0 at main.rs:5:5: 5:10
+ return; // scope 0 at main.rs:6:2: 6:2
+ }
+}
+
+fn main() -> () {
+ let mut _0: (); // return place in scope 0 at main.rs:8:11: 8:11
+ let _1: i32; // in scope 0 at main.rs:9:5: 9:10
+
+ bb0: {
+ _1 = foo() -> bb1; // scope 0 at main.rs:9:5: 9:10
+ // mir::Constant
+ // + span: main.rs:9:5: 9:8
+ // + literal: Const { ty: fn() -> i32 {foo}, val: Value(<ZST>) }
+ }
+
+ bb1: {
+ return; // scope 0 at main.rs:10:2: 10:2
+ }
+}
diff --git a/src/test/run-make/const_fn_mir/main.rs b/src/test/run-make/const_fn_mir/main.rs
new file mode 100644
index 000000000..e8552bd28
--- /dev/null
+++ b/src/test/run-make/const_fn_mir/main.rs
@@ -0,0 +1,10 @@
+// emit-mir
+// check-pass
+
+const fn foo() -> i32 {
+ 5 + 6
+}
+
+fn main() {
+ foo();
+}