Go: Use shared guards library - #22365
Draft
owen-mc wants to merge 29 commits into
Draft
Conversation
|
|
||
| /** 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) { |
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>
owen-mc
force-pushed
the
go/shared-guards
branch
from
August 17, 2026 19:16
f8092fc to
57db4c8
Compare
There was a problem hiding this comment.
CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
Agent-Logs-Url: https://github.com/github/codeql/sessions/d505ffcf-a693-4b67-9dc3-54fa92e27896 Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com>
Agent-Logs-Url: https://github.com/github/codeql/sessions/d505ffcf-a693-4b67-9dc3-54fa92e27896 Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com>
…brary Agent-Logs-Url: https://github.com/github/codeql/sessions/d505ffcf-a693-4b67-9dc3-54fa92e27896 Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com>
owen-mc
force-pushed
the
go/shared-guards
branch
from
August 17, 2026 21:55
57db4c8 to
def5d61
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.