Skip to content

Commit

Permalink
Build PDG without tracking assignments
Browse files Browse the repository at this point in the history
The event assignment-based PDG
construction steps were giving incorrect results
for indirect accesses, so remove them completely.
  • Loading branch information
ahomescu committed Jul 25, 2024
1 parent 8af09d1 commit 152c3ae
Showing 1 changed file with 12 additions and 49 deletions.
61 changes: 12 additions & 49 deletions pdg/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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),
Expand All @@ -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,
Expand All @@ -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()));
Expand All @@ -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)
}

Expand Down

0 comments on commit 152c3ae

Please sign in to comment.