Skip to content

Commit

Permalink
filter out non functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Medowhill committed Jan 22, 2024
1 parent 1d1aa87 commit 20ad6c6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
16 changes: 10 additions & 6 deletions src/relational/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl<'tcx> Analyzer<'tcx, '_> {

pub fn resolve_indirect_calls(&self, local: Local) -> HashSet<LocalDefId> {
self.alias_graph
.find_fn_may_aliases(self.local_def_id, local)
.find_fn_may_aliases(self.local_def_id, local, self.tcx)
}

pub fn locals_invalidated_by_call(&self, callee: LocalDefId) -> HashSet<(Local, usize)> {
Expand Down Expand Up @@ -485,17 +485,21 @@ impl<'tcx> Visitor<'tcx> for BodyVisitor<'tcx, '_> {
match func {
Operand::Copy(f) | Operand::Move(f) => {
assert!(f.projection.is_empty());
let callees = self.var_graph.find_fn_may_aliases(self.current_fn, f.local);
let callees =
self.var_graph
.find_fn_may_aliases(self.current_fn, f.local, self.tcx);
self.callees.extend(callees);
}
Operand::Constant(box constant) => {
if let ConstantKind::Val(value, ty) = constant.literal {
assert_eq!(value, ConstValue::ZeroSized);
let TyKind::FnDef(def_id, _) = ty.kind() else { unreachable!() };
let name = self.def_id_to_string(*def_id);
if let Some(def_id) = def_id.as_local() {
if !name.contains("{extern#") {
self.callees.insert(def_id);
if self.tcx.impl_of_method(*def_id).is_none() {
let name = self.def_id_to_string(*def_id);
if let Some(def_id) = def_id.as_local() {
if !name.contains("{extern#") {
self.callees.insert(def_id);
}
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/relational/semantics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,11 @@ impl<'tcx> Analyzer<'tcx, '_> {
let (d, d_deref) = AccPath::from_place(*dst, state);
assert!(!d_deref);
match name {
("", "option", _, _) | ("ptr", _, _, "is_null" | "offset_from") => true,
("", "clone", "Clone", "clone")
| (_, "ffi", _, _)
| ("ops", _, _, _)
| ("", "option", _, _)
| ("ptr", _, _, "is_null" | "offset_from") => true,
("", "slice", _, "as_ptr" | "as_mut_ptr") => {
let ptr = args[0].place().unwrap();
let (mut ptr, ptr_deref) = AccPath::from_place(ptr, state);
Expand Down
22 changes: 19 additions & 3 deletions src/steensgaard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
use disjoint_set::DisjointSet;
use etrace::some_or;
use lazy_static::lazy_static;
use rustc_hir::{ForeignItemKind, ItemKind};
use rustc_hir::{ForeignItemKind, Item, ItemKind, Node};
use rustc_middle::{
mir::{
interpret::{ConstValue, GlobalAlloc, Scalar},
Expand Down Expand Up @@ -541,7 +541,12 @@ impl AliasGraph {
aliases
}

pub fn find_fn_may_aliases(&self, f: LocalDefId, l: Local) -> HashSet<LocalDefId> {
pub fn find_fn_may_aliases(
&self,
f: LocalDefId,
l: Local,
tcx: TyCtxt<'_>,
) -> HashSet<LocalDefId> {
let id = VarId::Local(f, l.as_u32());
let node = self.id_to_node[&id];
let pointed_fn = self.points_to_fn[&node];
Expand All @@ -550,7 +555,18 @@ impl AliasGraph {
.iter()
.filter_map(|node| {
let VarId::Global(f) = node else { return None };
Some(*f)
let node = tcx.hir().find_by_def_id(*f).unwrap();
if matches!(
node,
Node::Item(Item {
kind: ItemKind::Fn(..),
..
})
) {
Some(*f)
} else {
None
}
})
.collect()
}
Expand Down

0 comments on commit 20ad6c6

Please sign in to comment.