-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
analyze: allow overriding dataflow for specific permissions (#1088)
This adds a new internal feature for overriding dataflow analysis for specific permissions of specific pointers. The `propagate` method of `dataflow` now takes an additional `updates_forbidden` set, which has a `PermissionSet` mask for every `PointerId`, and avoids adding or removing a permission for a `ptr` if the corresponding bit is set in `updates_forbidden[ptr]`. When `updates_forbidden` is used, the resulting permissions after running `dataflow` might not actually satisfy the dataflow constraints. This is designed to support the PDG "`NON_NULL` override" feature, where information about nullability from the PDG can override static analysis results, though that feature is not part of the current PR.
- Loading branch information
Showing
6 changed files
with
171 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#![feature(register_tool)] | ||
#![register_tool(c2rust_analyze_test)] | ||
|
||
// TODO: All the pointers here are currently inferred to be non-`UNIQUE`, even though the access | ||
// patterns look fine. | ||
|
||
use std::ptr; | ||
|
||
// CHECK-LABEL: final labeling for "f" | ||
fn f(cond: bool) { | ||
let x = 1_i32; | ||
// CHECK: ([[@LINE+1]]: mut y): {{.*}}, type = (empty)# | ||
let mut y = ptr::addr_of!(x); | ||
if cond { | ||
y = 0 as *const _; | ||
} | ||
// The expression `y` is considered nullable even though it's passed for argument `p` of `g`, | ||
// which is forced to be `NON_NULL`. | ||
// CHECK: ([[@LINE+1]]: y): {{.*}}, type = (empty)# | ||
g(cond, y); | ||
} | ||
|
||
// CHECK-LABEL: final labeling for "g" | ||
// `p` should be non-null, as it's forced to be by the attribute. This emulates the "unsound" PDG | ||
// case, where a variable is forced to stay `NON_NULL` even though a null possibly flows into it. | ||
// CHECK: ([[@LINE+2]]: p): {{.*}}, type = NON_NULL# | ||
#[c2rust_analyze_test::force_non_null_args] | ||
fn g(cond: bool, p: *const i32) { | ||
// `q` is not forced to be `NON_NULL`, so it should be inferred nullable due to the null | ||
// assignment below. | ||
// CHECK: ([[@LINE+1]]: mut q): {{.*}}, type = (empty)# | ||
let mut q = p; | ||
if cond { | ||
q = 0 as *const _; | ||
} | ||
// `r` is derived from `q` (and is not forced), so it should also be nullable. | ||
// CHECK: ([[@LINE+1]]: r): {{.*}}, type = (empty)# | ||
let r = q; | ||
} | ||
|