Skip to content

Commit

Permalink
analyze: add adjust_unsize test case
Browse files Browse the repository at this point in the history
  • Loading branch information
spernsteiner committed Sep 25, 2023
1 parent b57fa64 commit c096a7f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions c2rust-analyze/tests/filecheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ macro_rules! define_tests {

define_tests! {
addr_of,
adjust_unsize,
aggregate1,
algo_md5,
alias1,
Expand Down
28 changes: 28 additions & 0 deletions c2rust-analyze/tests/filecheck/adjust_unsize.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

// CHECK-LABEL: unsafe fn f
// CHECK-SAME: <'[[LT:[a-z0-9]+]]>(p: &'[[LT]] mut (u8)) {
unsafe fn f(p: *mut u8) {
*p = 1;
}

// CHECK-LABEL: unsafe fn pass_arr_simple()
unsafe fn pass_arr_simple() {
let mut arr: [u8; 3] = [0; 3];
// CHECK: f(&mut (&mut (arr) as &mut [u8])[0]);
f(arr.as_mut_ptr());
}

// CHECK-LABEL: unsafe fn pass_arr_explicit_ref()
unsafe fn pass_arr_explicit_ref() {
let mut arr: [u8; 3] = [0; 3];
// CHECK: f(&mut (&mut *((&mut arr)) as &mut [u8])[0]);
f((&mut arr).as_mut_ptr());
}

// CHECK-LABEL: unsafe fn pass_arr_ufcs()
unsafe fn pass_arr_ufcs() {
let mut arr: [u8; 3] = [0; 3];
// CHECK: f(&mut (&mut *(&mut arr) as &mut [u8])[0]);
f(<[_]>::as_mut_ptr(&mut arr));
}

0 comments on commit c096a7f

Please sign in to comment.