Skip to content

Commit

Permalink
Add Drop terminator to SMIR
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino committed Apr 20, 2023
1 parent 2f50334 commit 9a89ef0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
6 changes: 5 additions & 1 deletion compiler/rustc_smir/src/rustc_smir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ fn rustc_terminator_to_terminator(
Terminate => Terminator::Abort,
Return => Terminator::Return,
Unreachable => Terminator::Unreachable,
Drop { .. } => todo!(),
Drop { place, target, unwind } => Terminator::Drop {
place: rustc_place_to_place(place),
target: target.as_usize(),
unwind: rustc_unwind_to_unwind(unwind),
},
Call { func, args, destination, target, unwind, from_hir_call: _, fn_span: _ } => {
Terminator::Call {
func: rustc_op_to_op(func),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_smir/src/stable_mir/mir/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub enum Terminator {
Drop {
place: Place,
target: usize,
unwind: Option<usize>,
unwind: UnwindAction,
},
Call {
func: Operand,
Expand Down
13 changes: 12 additions & 1 deletion tests/ui-fulldeps/stable-mir/crate-info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ fn test_stable_mir(tcx: TyCtxt<'_>) {
stable_mir::mir::Terminator::Call { .. } => {}
other => panic!("{other:?}"),
}

let drop = get_item(tcx, &items, (DefKind::Fn, "drop")).unwrap();
let body = drop.body();
assert_eq!(body.blocks.len(), 2);
let block = &body.blocks[0];
match &block.terminator {
stable_mir::mir::Terminator::Drop { .. } => {}
other => panic!("{other:?}"),
}
}

// Use internal API to find a function in a crate.
Expand Down Expand Up @@ -131,7 +140,9 @@ fn generate_input(path: &str) -> std::io::Result<()> {
let x_64 = foo::bar(x);
let y_64 = foo::bar(y);
x_64.wrapping_add(y_64)
}}"#
}}
pub fn drop(_: String) {{}}"#
)?;
Ok(())
}

0 comments on commit 9a89ef0

Please sign in to comment.