Expand description
Def-use chain queries over SSA form (DF-11).
Look up uses of an SSA definition:
use std::collections::HashMap;
use weir::def_use::try_def_use_chain;
use weir::ssa::SsaForm;
let form = SsaForm {
phi_nodes: HashMap::new(),
renamed_usages: HashMap::new(),
def_use_chains: {
let mut m = HashMap::new();
m.insert(7, vec![3, 5, 9]);
m
},
};
assert_eq!(try_def_use_chain(&form, 7).unwrap(), vec![3, 5, 9]);DF-11 - Def-use chain query over a constructed SSA form.
For a given SSA-renamed definition site (say %tmp.3 = …),
return the bitset of nodes that USE that definition. This is the
canonical “what reads this def” query that CodeQL exposes as
DataFlow::Node::getUses() and that every taint rule reaches for
when answering “did the value defined here reach a sink without
being overwritten.”
Composes:
- [
super::ssa::SsaForm::def_use_chains] - the per-SSA-version use list built by Cytron + variable renaming during SSA construction. We index it by the SSA version of the supplied definition site and emit a bitset over node ids.
Soundness: Exact. The
def-use chain is computed by SSA construction, which is sound by
construction; this primitive is a pure query against that
pre-built table.
Structs§
- DefUse
- Marker type for the def-use dataflow primitive.
Functions§
- def_
use_ query - Build a def-use query Program over a precomputed use bitset.
- try_
def_ use_ chain - Look up uses of an SSA definition version. Returns a sorted dense
vector of
node_idvalues for every use ofdef_version. - try_
def_ use_ chain_ bitset - Pack the use-set for
def_versioninto a bitset overnode_count. Each bitiis1iff nodeiis recorded as a use of the supplied definition version. Bits beyondnode_countare zero.