From 634917f280f7e8576c9453c671cc87481fa10653 Mon Sep 17 00:00:00 2001 From: Andrei Homescu Date: Thu, 13 Jun 2024 00:41:07 -0700 Subject: [PATCH] Build PDG without tracking assignments The event assignment-based PDG construction steps were giving incorrect results for indirect accesses, so remove them completely. --- pdg/src/builder.rs | 61 +++++++++------------------------------------- 1 file changed, 12 insertions(+), 49 deletions(-) diff --git a/pdg/src/builder.rs b/pdg/src/builder.rs index c290b46f8..467ceff29 100644 --- a/pdg/src/builder.rs +++ b/pdg/src/builder.rs @@ -122,7 +122,7 @@ fn update_provenance( Realloc { new_ptr, .. } => { provenances.insert(new_ptr, mapping); } - Offset(_, _, new_ptr) => { + Offset(_, _, new_ptr) | Project(_, new_ptr, _) => { provenances.insert(new_ptr, mapping); } CopyRef => { @@ -151,7 +151,7 @@ pub fn add_node( let node_kind = event.kind.to_node_kind(func.id, address_taken)?; let this_id = func.id; - let (src_fn, dest_fn) = match event_metadata.transfer_kind { + let (_src_fn, dest_fn) = match event_metadata.transfer_kind { TransferKind::None => (this_id, this_id), TransferKind::Arg(id) => (this_id, id), TransferKind::Ret(id) => (id, this_id), @@ -173,37 +173,22 @@ pub fn add_node( .iter() .rposition(|n| { if let (Some(d), Some(s)) = (&n.dest, &event_metadata.source) { - d == s + // TODO: Ignore direct assignments with projections for now, + // e.g., `_1.0 = _2;`. We should later add support for + // assignments to sub-fields, e.g. + // ``` + // _1 = _2; + // _1.0 = _3; + // _1 = _4; + // ``` + d == s && s.projection.is_empty() } else { false } }) .map(|nid| (gid, NodeId::from(nid))) }); - - let source = direct_source.or_else(|| { - event_metadata.source.as_ref().and_then(|src| { - let latest_assignment = graphs.latest_assignment.get(&(src_fn, src.local)).cloned(); - if !src.projection.is_empty() { - if let Some((gid, _)) = latest_assignment { - if let Some((nid, n)) = graphs.graphs[gid].nodes.iter_enumerated().rev().next() - { - if let NodeKind::Project(..) = n.kind { - return Some((gid, nid)); - } - } - } - } - - if !matches!(event.kind, EventKind::AddrOfLocal(..)) && src.projection.is_empty() { - latest_assignment - } else if let EventKind::Project(..) = event.kind { - latest_assignment - } else { - provenance - } - }) - }); + let source = direct_source.or(provenance); let function = Func { id: dest_fn, @@ -224,8 +209,6 @@ pub fn add_node( }; let graph_id = source - .or(direct_source) - .or(provenance) .and_then(|p| parent(&node_kind, p)) .map(|(gid, _)| gid) .unwrap_or_else(|| graphs.graphs.push(Graph::new())); @@ -238,26 +221,6 @@ pub fn add_node( (graph_id, node_id), ); - if let Some(dest) = &event_metadata.destination { - let unique_place = (dest_fn, dest.local); - let last_setting = (graph_id, node_id); - - if let Some(last @ (last_gid, last_nid)) = - graphs.latest_assignment.insert(unique_place, last_setting) - { - if !dest.projection.is_empty() - && graphs.graphs[last_gid].nodes[last_nid] - .dest - .as_ref() - .unwrap() - .projection - .is_empty() - { - graphs.latest_assignment.insert(unique_place, last); - } - } - } - Some(node_id) }