about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTomasz Miąsko <tomasz.miasko@gmail.com>2023-01-19 00:00:00 +0000
committerTomasz Miąsko <tomasz.miasko@gmail.com>2023-01-19 11:53:33 +0100
commitca3d55e32d762ca0acb0676aac70848c559c7f06 (patch)
tree286115a894f3fb403df26c4ad90e9679c7d5b969
parent65d2f2a5f9c323c88d1068e8e90d0b47a20d491c (diff)
downloadrust-ca3d55e32d762ca0acb0676aac70848c559c7f06.tar.gz
rust-ca3d55e32d762ca0acb0676aac70848c559c7f06.zip
Custom MIR: Support storage statements
-rw-r--r--compiler/rustc_mir_build/src/build/custom/parse/instruction.rs6
-rw-r--r--library/core/src/intrinsics/mir.rs2
-rw-r--r--tests/mir-opt/building/custom/simple_assign.rs2
-rw-r--r--tests/mir-opt/building/custom/simple_assign.simple.built.after.mir12
4 files changed, 17 insertions, 5 deletions
diff --git a/compiler/rustc_mir_build/src/build/custom/parse/instruction.rs b/compiler/rustc_mir_build/src/build/custom/parse/instruction.rs
index dca4906c07d..0bca02589bc 100644
--- a/compiler/rustc_mir_build/src/build/custom/parse/instruction.rs
+++ b/compiler/rustc_mir_build/src/build/custom/parse/instruction.rs
@@ -12,6 +12,12 @@ use super::{parse_by_kind, PResult, ParseCtxt};
 impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
     pub fn parse_statement(&self, expr_id: ExprId) -> PResult<StatementKind<'tcx>> {
         parse_by_kind!(self, expr_id, _, "statement",
+            @call("mir_storage_live", args) => {
+                Ok(StatementKind::StorageLive(self.parse_local(args[0])?))
+            },
+            @call("mir_storage_dead", args) => {
+                Ok(StatementKind::StorageDead(self.parse_local(args[0])?))
+            },
             @call("mir_retag", args) => {
                 Ok(StatementKind::Retag(RetagKind::Default, Box::new(self.parse_place(args[0])?)))
             },
diff --git a/library/core/src/intrinsics/mir.rs b/library/core/src/intrinsics/mir.rs
index 399d54f18c5..e3157b66902 100644
--- a/library/core/src/intrinsics/mir.rs
+++ b/library/core/src/intrinsics/mir.rs
@@ -259,6 +259,8 @@ define!("mir_unreachable", fn Unreachable() -> BasicBlock);
 define!("mir_drop", fn Drop<T>(place: T, goto: BasicBlock));
 define!("mir_drop_and_replace", fn DropAndReplace<T>(place: T, value: T, goto: BasicBlock));
 define!("mir_call", fn Call<T>(place: T, goto: BasicBlock, call: T));
+define!("mir_storage_live", fn StorageLive<T>(local: T));
+define!("mir_storage_dead", fn StorageDead<T>(local: T));
 define!("mir_retag", fn Retag<T>(place: T));
 define!("mir_move", fn Move<T>(place: T) -> T);
 define!("mir_static", fn Static<T>(s: T) -> &'static T);
diff --git a/tests/mir-opt/building/custom/simple_assign.rs b/tests/mir-opt/building/custom/simple_assign.rs
index ec6dbe1d052..db041aab239 100644
--- a/tests/mir-opt/building/custom/simple_assign.rs
+++ b/tests/mir-opt/building/custom/simple_assign.rs
@@ -11,12 +11,14 @@ pub fn simple(x: i32) -> i32 {
         let temp2: _;
 
         {
+            StorageLive(temp1);
             temp1 = x;
             Goto(exit)
         }
 
         exit = {
             temp2 = Move(temp1);
+            StorageDead(temp1);
             RET = temp2;
             Return()
         }
diff --git a/tests/mir-opt/building/custom/simple_assign.simple.built.after.mir b/tests/mir-opt/building/custom/simple_assign.simple.built.after.mir
index d7560fde69c..743016708c5 100644
--- a/tests/mir-opt/building/custom/simple_assign.simple.built.after.mir
+++ b/tests/mir-opt/building/custom/simple_assign.simple.built.after.mir
@@ -6,13 +6,15 @@ fn simple(_1: i32) -> i32 {
     let mut _3: i32;                     // in scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL
 
     bb0: {
-        _2 = _1;                         // scope 0 at $DIR/simple_assign.rs:+6:13: +6:22
-        goto -> bb1;                     // scope 0 at $DIR/simple_assign.rs:+7:13: +7:23
+        StorageLive(_2);                 // scope 0 at $DIR/simple_assign.rs:+6:13: +6:31
+        _2 = _1;                         // scope 0 at $DIR/simple_assign.rs:+7:13: +7:22
+        goto -> bb1;                     // scope 0 at $DIR/simple_assign.rs:+8:13: +8:23
     }
 
     bb1: {
-        _3 = move _2;                    // scope 0 at $DIR/simple_assign.rs:+11:13: +11:32
-        _0 = _3;                         // scope 0 at $DIR/simple_assign.rs:+12:13: +12:24
-        return;                          // scope 0 at $DIR/simple_assign.rs:+13:13: +13:21
+        _3 = move _2;                    // scope 0 at $DIR/simple_assign.rs:+12:13: +12:32
+        StorageDead(_2);                 // scope 0 at $DIR/simple_assign.rs:+13:13: +13:31
+        _0 = _3;                         // scope 0 at $DIR/simple_assign.rs:+14:13: +14:24
+        return;                          // scope 0 at $DIR/simple_assign.rs:+15:13: +15:21
     }
 }