Skip to content

Commit

Permalink
analyze: fix panic on addr_of!(...) as ... (#945)
Browse files Browse the repository at this point in the history
Fixes the panic described in
#839 (comment)
  • Loading branch information
spernsteiner committed Jun 5, 2023
2 parents db19cef + 6d93064 commit f082f17
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion c2rust-analyze/src/rewrite/expr/mir_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,9 @@ impl<'a, 'tcx> ExprRewriteVisitor<'a, 'tcx> {
Rvalue::AddressOf(mutbl, pl) => {
self.enter_rvalue_place(0, |v| v.visit_place(pl));
if let Some(expect_ty) = expect_ty {
let desc = type_desc::perms_to_desc(
let desc = type_desc::perms_to_desc_with_pointee(
self.acx.tcx(),
self.acx.type_of(pl).ty,
expect_ty.ty,
self.perms[expect_ty.label],
self.flags[expect_ty.label],
Expand Down
7 changes: 7 additions & 0 deletions c2rust-analyze/tests/filecheck/addr_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@ fn shared_ref_with_struct() {
// CHECK-DAG: let y = &(x.a);
let y = std::ptr::addr_of!(x.a);
}

// CHECK-LABEL: fn cast_array_to_ptr_explicit(s: &[u8; 0]) {
pub fn cast_array_to_ptr_explicit(s: &[u8; 0]) {
// For now, this doesn't get rewritten - we're just checking that the analysis doesn't panic.
// CHECK-DAG: std::ptr::addr_of!(*s) as *const u8
std::ptr::addr_of!(*s) as *const u8;
}

0 comments on commit f082f17

Please sign in to comment.