Data Flow Testing - Step-by-Step (DEFs & du-pairs)
Step-by-step process:
Step 1 — Find all DEFs of A
Scan every line, look for LHS assignment or input():
node 1: input(A,B) ← DEF of A ✅
node 2: A = A+7 ← DEF of A ✅ (LHS)
Step 2 — Find all USEs of A
Scan every line, look for RHS, predicates, output():
node 2: A = A+7 ← USE of A (c-use, RHS) ✅
node 3: if (A>10) ← USE of A (p-use, predicate) → edge <3,4> and <3,5> ✅
node 4: B = A+B ← USE of A (c-use, RHS) ✅
node 5: output(A,B) ← USE of A (c-use) ✅
Step 3 — For each DEF, trace to every USE
Ask: "is there a def-clear path from this DEF to this USE?"
Start with def@1, pair with every use:
| du-pair | Path exists? | def-clear? |
|---|---|---|
| (1, 2) | 1→2 ✅ | no redef ✅ |
| (1, 4) | 1→3→4 ✅ | no redef ✅ |
| (1, 5) | 1→3→4→5 and 1→3→5 ✅ | no redef ✅ |
(1, <3,4>) | 1→3→4 ✅ | no redef ✅ |
(1, <3,5>) | 1→3→5 ✅ | no redef ✅ |
Then def@2, pair with every use reachable after node 2:
| du-pair | Path exists? | def-clear? |
|---|---|---|
| (2, 4) | 2→3→4 ✅ | no redef ✅ |
| (2, 5) | 2→3→4→5 and 2→3→5 ✅ | no redef ✅ |
(2, <3,4>) | 2→3→4 ✅ | no redef ✅ |
(2, <3,5>) | 2→3→5 ✅ | no redef ✅ |
Step 4 — Ask: can def@1 reach node 2's USE?
⚠️ Wait — can (1, 2) exist? node 2 is
A = A+7— A is used on RHS before being redefined on LHS
Yes! The USE happens first → (1, 2) is valid ✅
But after node 2, def@1 is killed — so no (1, USE) paths that go through node 2 exist.
Mental checklist:
1. Find all DEFs → which nodes?
2. Find all USEs → c-use (node) or p-use (edge)?
3. For each DEF → trace to each USE → def-clear path?
4. If redefined in between → that du-pair from original DEF is dead
5. Start a new DEF from the redefinition node
The CFG is your map — just follow the arrows and ask "does anything redefine this variable before I reach the use?" 🎯
| du-pair | path(s) |
|---|---|
| (1,2) | <1,2> |
| (1,4) | <1,3,4> |
| (1,5) | <1,3,4,5> |
<1,3,5> | |
(1,<3,4>) | <1,3,4> |
(1,<3,5>) | <1,3,5> |
| (2,4) | <2,3,4> |
| (2,5) | <2,3,4,5> |
<2,3,5> | |
(2,<3,4>) | <2,3,4> |
(2,<3,5>) | <2,3,5> |