Skip to content

Commit

Permalink
Use PDG to remove NON_NULL from pointers in static analysis
Browse files Browse the repository at this point in the history
Remove the NON_NULL permission from all nodes in
the null graph from the PDG.
  • Loading branch information
ahomescu committed Aug 19, 2024
1 parent 3875441 commit 118a9fb
Showing 1 changed file with 19 additions and 26 deletions.
45 changes: 19 additions & 26 deletions c2rust-analyze/src/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -997,36 +997,29 @@ fn run(tcx: TyCtxt) {
}
};

let node_info = match n.info.as_ref() {
Some(x) => x,
None => {
eprintln!(
"pdg: {}: node with dest {:?} is missing NodeInfo",
n.function.name, dest
);
info.acx_data.set(acx.into_data());
continue;
}
};

let old_perms = asn.perms()[ptr];
let mut perms = old_perms;
if node_info.flows_to.load.is_some() {
perms.insert(PermissionSet::READ);
if g.is_null {
perms.remove(PermissionSet::NON_NULL);
}
if node_info.flows_to.store.is_some() {
perms.insert(PermissionSet::WRITE);
}
if node_info.flows_to.pos_offset.is_some() {
perms.insert(PermissionSet::OFFSET_ADD);
}
if node_info.flows_to.neg_offset.is_some() {
perms.insert(PermissionSet::OFFSET_SUB);
}
if !node_info.unique {
perms.remove(PermissionSet::UNIQUE);

if let Some(node_info) = n.info.as_ref() {
if node_info.flows_to.load.is_some() {
perms.insert(PermissionSet::READ);
}
if node_info.flows_to.store.is_some() {
perms.insert(PermissionSet::WRITE);
}
if node_info.flows_to.pos_offset.is_some() {
perms.insert(PermissionSet::OFFSET_ADD);
}
if node_info.flows_to.neg_offset.is_some() {
perms.insert(PermissionSet::OFFSET_SUB);
}
if !node_info.unique {
perms.remove(PermissionSet::UNIQUE);
}
}
// TODO: PermissionSet::NON_NULL

if perms != old_perms {
let added = perms & !old_perms;
Expand Down

0 comments on commit 118a9fb

Please sign in to comment.