Skip to content

Commit 837d907

Browse files
Copilotowen-mc
andauthored
Add captured variable liveness fix and fix override annotations
Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com> Agent-Logs-Url: https://github.com/github/codeql/sessions/b400ebd5-4095-401e-8811-fb550600b3c4
1 parent 6014289 commit 837d907

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

go/ql/lib/semmle/go/dataflow/SsaImpl.qll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,20 @@ private module Internal {
9393

9494
/**
9595
* Holds if the `i`th node of basic block `bb` reads source variable `v`.
96+
*
97+
* We also add a synthetic uncertain read at the exit node of the declaring
98+
* function for captured variables. This ensures that definitions of captured
99+
* variables are included in the SSA graph even when the variable is not
100+
* locally read in the declaring function (but may be read by a nested function).
96101
*/
97102
predicate variableRead(BasicBlock bb, int i, SourceVariable v, boolean certain) {
98103
useAt(bb, i, v) and certain = true
104+
or
105+
v.isCaptured() and
106+
bb.getScope() = v.getDeclaringFunction() and
107+
bb.getLastNode().isExitNode() and
108+
i = bb.length() - 1 and
109+
certain = false
99110
}
100111
}
101112
}

0 commit comments

Comments
 (0)