Skip to content

Commit

Permalink
Handle new statement kind Deinit
Browse files Browse the repository at this point in the history
We codegen an assignment to non-det value per documentation. See more
information here:
 - rust-lang/rust#95125
  • Loading branch information
celinval committed May 11, 2022
1 parent ddd6005 commit b378f72
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion kani-compiler/src/codegen_cprover_gotoc/codegen/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,23 @@ impl<'tcx> GotocCtx<'tcx> {
.assign(self.codegen_rvalue(r), Location::none())
}
}
StatementKind::Deinit(place) => {
// From rustc doc: "This writes `uninit` bytes to the entire place."
// Thus, we assign nondet() value to the entire place.
let dst_mir_ty = self.place_ty(place);
let dst_type = self.codegen_ty(dst_mir_ty);
let layout = self.layout_of(dst_mir_ty);
if layout.is_zst() || self.ignore_var_ty(dst_mir_ty) {
// We ignore assignment for all zero size types
// Ignore generators too for now:
// https://github.com/model-checking/kani/issues/416
Stmt::skip(Location::none())
} else {
unwrap_or_return_codegen_unimplemented_stmt!(self, self.codegen_place(place))
.goto_expr
.assign(dst_type.nondet(), Location::none())
}
}
StatementKind::SetDiscriminant { place, variant_index } => {
// this requires place points to an enum type.
let pt = self.place_ty(place);
Expand Down Expand Up @@ -740,7 +757,6 @@ impl<'tcx> GotocCtx<'tcx> {
| StatementKind::AscribeUserType(_, _)
| StatementKind::Nop
| StatementKind::Coverage { .. } => Stmt::skip(Location::none()),
StatementKind::Deinit(_) => todo!("Unimplemented statement. See: "),
}
.with_location(self.codegen_span(&stmt.source_info.span))
}
Expand Down

0 comments on commit b378f72

Please sign in to comment.