Skip to content

Commit

Permalink
analyze: add non_null test case
Browse files Browse the repository at this point in the history
  • Loading branch information
spernsteiner committed Apr 12, 2024
1 parent a5ffd1e commit 787919a
Show file tree
Hide file tree
Showing 2 changed files with 35 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 @@ -55,6 +55,7 @@ define_tests! {
insertion_sort_driver,
insertion_sort_rewrites,
known_fn,
non_null,
offset1,
offset2,
pointee,
Expand Down
34 changes: 34 additions & 0 deletions c2rust-analyze/tests/filecheck/non_null.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use std::ptr;

// CHECK-LABEL: final labeling for "f"
fn f(cond: bool) {
let x = 1_i32;
// CHECK: ([[@LINE+1]]: mut y): {{.*}}, type = UNIQUE#
let mut y = ptr::addr_of!(x);
if cond {
y = ptr::null();
}
}

// CHECK-LABEL: final labeling for "g"
fn g(cond: bool) {
let x = 1_i32;
// CHECK: ([[@LINE+1]]: y): {{.*}}, type = UNIQUE | NON_NULL#
let y = ptr::addr_of!(x);
if cond {
let z = ptr::null::<i32>();
}
}

// CHECK-LABEL: final labeling for "h"
fn h(cond: bool) {
let x = 1_i32;
// CHECK: ([[@LINE+1]]: y): {{.*}}, type = UNIQUE | NON_NULL#
let y = ptr::addr_of!(x);
// CHECK: ([[@LINE+1]]: z): {{.*}}, type = UNIQUE#
let z = if cond {
y
} else {
ptr::null()
};
}

0 comments on commit 787919a

Please sign in to comment.