about summary refs log tree commit diff
diff options
context:
space:
mode:
authorKirby Linvill <kjlinvill@gmail.com>2023-10-26 00:22:56 +0100
committerKirby Linvill <kjlinvill@gmail.com>2023-10-26 00:22:56 +0100
commitbac7d5b52cc60754e0555f96c3501e1531bbf6fe (patch)
tree7f2875691512db1840389192f73f9dce581613e2
parent4b23bd47348a6325ee332e48b9d16e1b65d1c500 (diff)
downloadrust-bac7d5b52cc60754e0555f96c3501e1531bbf6fe.tar.gz
rust-bac7d5b52cc60754e0555f96c3501e1531bbf6fe.zip
Add test for smir locals
-rw-r--r--tests/ui-fulldeps/stable-mir/crate-info.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/ui-fulldeps/stable-mir/crate-info.rs b/tests/ui-fulldeps/stable-mir/crate-info.rs
index 33673cd131f..ed6b786f5e1 100644
--- a/tests/ui-fulldeps/stable-mir/crate-info.rs
+++ b/tests/ui-fulldeps/stable-mir/crate-info.rs
@@ -140,6 +140,29 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
     // Ensure we don't panic trying to get the body of a constant.
     foo_const.body();
 
+    let locals_fn = get_item(&items, (DefKind::Fn, "locals")).unwrap();
+    let body = locals_fn.body();
+    assert_eq!(body.locals().len(), 4);
+    assert_matches!(
+        body.ret_local().ty.kind(),
+        stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Char)
+    );
+    assert_eq!(body.arg_locals().len(), 2);
+    assert_matches!(
+        body.arg_locals()[0].ty.kind(),
+        stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Int(stable_mir::ty::IntTy::I32))
+    );
+    assert_matches!(
+        body.arg_locals()[1].ty.kind(),
+        stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Uint(stable_mir::ty::UintTy::U64))
+    );
+    assert_eq!(body.inner_locals().len(), 1);
+    // If conditions have an extra inner local to hold their results
+    assert_matches!(
+        body.inner_locals()[0].ty.kind(),
+        stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Bool)
+    );
+
     ControlFlow::Continue(())
 }
 
@@ -211,6 +234,14 @@ fn generate_input(path: &str) -> std::io::Result<()> {
 
     pub fn assert(x: i32) -> i32 {{
         x + 1
+    }}
+
+    pub fn locals(a: i32, _: u64) -> char {{
+        if a > 5 {{
+            'a'
+        }} else {{
+            'b'
+        }}
     }}"#
     )?;
     Ok(())