Skip to content

Go: Use shared guards library - #22365

Draft
owen-mc wants to merge 29 commits into
github:mainfrom
owen-mc:go/shared-guards
Draft

Go: Use shared guards library#22365
owen-mc wants to merge 29 commits into
github:mainfrom
owen-mc:go/shared-guards

Conversation

@owen-mc

@owen-mc owen-mc commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

No description provided.


/** Holds if arguments at position `apos` match parameters at position `ppos`. */
pragma[inline]
predicate parameterMatch(ParameterPosition ppos, ArgumentPosition apos) { ppos = apos }
* idiom.
*/
pragma[inline]
predicate guardEnsures(Expr e, boolean b, BasicBlock bb) { e.(Guard).controls(bb, b) }
Node g, ControlFlow::ConditionGuardNode guard, Node nd, SsaWithFields ap, P param
) {
guards(g, guard, nd, param) and nd = ap.getAUse()
private predicate guards(Node g, Guard guard, boolean branch, Node nd, SsaWithFields ap, P param) {
owen-mc and others added 25 commits August 17, 2026 17:53
Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com>
Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com>
Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com>
Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com>
Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com>
Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com>
Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com>
Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com>
Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com>
Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com>
Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com>
Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com>
Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com>
Increment/decrement statements previously produced three control-flow
nodes: an 'implicit-one' node for the constant 1, an 'incdec-rhs' node
for the 'operand + 1' value, and the write node. The implicit-one node
existed only to serve as the right operand of the increment's binary
operation model.

Remove the implicit-one node, modelling the implicit constant 1 directly
on the incdec-rhs instruction. This saves one CFG node per inc/dec. The
inc/dec disjunct of BinaryOperationNode is dropped as well; it only fed
string-concatenation taint (impossible for ++/--) and GVN of a synthetic
node, so no data-flow results are lost.

Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com>
A compound assignment (`x += y`) previously produced two sequential
control-flow nodes: a 'compound-rhs' node computing the binary operation
`x + y`, followed by an 'assign:0' write node storing the result.

Make the compound-rhs instruction itself perform the write (it becomes a
WriteInstruction whose right-hand side is its own value), and stop
emitting the separate assign:0 node for compound assignments. This saves
one CFG node per compound assignment while preserving the BinaryOperationNode
model (so string-concatenation taint through `s += ...` still holds) and
SSA semantics (the def value is the binary operation).

Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com>
A slice expression with omitted bounds (e.g. `s[:]`, `s[a:]`, `s[:b]`)
previously created up to three synthetic control-flow nodes: implicit-low
(constant 0), implicit-high (length) and implicit-max (capacity). These
carried no data-flow value beyond the implicit lower bound of 0.

Stop emitting these nodes: control flow now skips directly to the next
present bound (or the slice evaluation). SliceInstruction.getLow/getHigh/
getMax return only explicit bounds. The one consumer of the implicit
lower bound, StringOps' HasPrefix_Substring, now treats an absent lower
bound as 0. No data-flow or StringOps results change.

Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com>
A named result variable previously created two additional nodes:
'result-zero-init:i' computing the zero value, and 'result-init:i'
writing that value into the result variable. The result-init node
existed only to write the value already computed by result-zero-init.

Make the result-zero-init instruction perform the write itself
(InitResultInstruction is now keyed on result-zero-init with its own
value as RHS) and drop the separate result-init node. All zero-value
constant semantics stay on the same node, so GVN and constant analysis
are unchanged; the only data-flow change is the SSA def relabeling
(result-init -> result-zero-init) with no flow loss.

Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com>
A positional element of an array or slice literal (e.g. the elements of
[]T{a, b}) previously created a 'lit-index' node holding its implicit
index constant (0, 1, ...), in addition to the 'lit-init' write node.

Array and slice content flow is index-insensitive (the store step
ignores the element index), map literals always use explicit keys, and
literal bases are not tracked by VariableWithFields, so the implicit
index value is never actually consumed. Drop the 'lit-index' node and
let the lit-init instruction act as its own opaque index. All 100
data-flow library tests pass unchanged, confirming no content-flow loss.

Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com>
Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com>
Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com>
Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com>
Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com>
Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com>
In Go, sub-expressions of a constant expression are folded at compile time and never evaluated at runtime, so they shouldn't get evaluation nodes.

Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com>
Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com>

@github-advanced-security github-advanced-security AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants