Skip to main content

Module def_use

Module def_use 

Source
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_id values for every use of def_version.
try_def_use_chain_bitset
Pack the use-set for def_version into a bitset over node_count. Each bit i is 1 iff node i is recorded as a use of the supplied definition version. Bits beyond node_count are zero.