From 56cb087bf1b7f8ae79c224135fd0942b8de0700c Mon Sep 17 00:00:00 2001 From: Andrei Homescu Date: Wed, 24 Apr 2024 22:17:09 -0700 Subject: [PATCH] Use PDG to remove NON_NULL from pointers in static analysis Remove the NON_NULL permission from all nodes in the null graph from the PDG. --- c2rust-analyze/src/analyze.rs | 45 +++++++++++++++-------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/c2rust-analyze/src/analyze.rs b/c2rust-analyze/src/analyze.rs index 41efc348c..f4eddf544 100644 --- a/c2rust-analyze/src/analyze.rs +++ b/c2rust-analyze/src/analyze.rs @@ -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;