Skip to content

Swift: Update SSA to reference the new use-use predicates. #19177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions swift/ql/lib/codeql/swift/dataflow/Ssa.qll
Original file line number Diff line number Diff line change
Expand Up @@ -151,25 +151,24 @@ module Ssa {

cached
ControlFlowNode getAFirstRead() {
exists(SsaInput::BasicBlock bb1, int i1, SsaInput::BasicBlock bb2, int i2 |
this.definesAt(_, bb1, i1) and
SsaImpl::adjacentDefRead(this, bb1, i1, bb2, i2) and
result = bb2.getNode(i2)
exists(SsaInput::BasicBlock bb, int i |
SsaImpl::firstUse(this, bb, i, true) and
result = bb.getNode(i)
)
}

cached
predicate adjacentReadPair(ControlFlowNode read1, ControlFlowNode read2) {
read1 = this.getARead() and
exists(SsaInput::BasicBlock bb1, int i1, SsaInput::BasicBlock bb2, int i2 |
read1 = bb1.getNode(i1) and
SsaInput::variableRead(bb1, i1, _, true) and
SsaImpl::adjacentDefRead(this, bb1, i1, bb2, i2) and
SsaImpl::adjacentUseUse(bb1, i1, bb2, i2, _, true) and
read2 = bb2.getNode(i2)
)
}

cached
predicate lastRefRedef(SsaInput::BasicBlock bb, int i, Definition next) {
deprecated predicate lastRefRedef(SsaInput::BasicBlock bb, int i, Definition next) {
SsaImpl::lastRefRedef(this, bb, i, next)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,8 @@ private class CaptureNodeImpl extends CaptureNode, NodeImpl {
}

private predicate localFlowSsaInput(Node nodeFrom, Ssa::Definition def, Ssa::Definition next) {
exists(BasicBlock bb, int i | def.lastRefRedef(bb, i, next) |
def.definesAt(_, bb, i) and
def = nodeFrom.asDefinition()
)
next.(Ssa::PhiDefinition).getAPhiInput() = def and
def = nodeFrom.asDefinition()
}

/** A collection of cached types and predicates to be evaluated in the same stage. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ edges
| test.swift:6:19:6:26 | call to source() | test.swift:7:15:7:15 | t1 | provenance | |
| test.swift:6:19:6:26 | call to source() | test.swift:9:15:9:15 | t1 | provenance | |
| test.swift:6:19:6:26 | call to source() | test.swift:10:15:10:15 | t2 | provenance | |
| test.swift:6:19:6:26 | call to source() | test.swift:15:15:15:15 | t2 | provenance | |
| test.swift:25:20:25:27 | call to source() | test.swift:29:18:29:21 | x | provenance | |
| test.swift:26:26:26:33 | call to source() | test.swift:29:26:29:29 | y | provenance | |
| test.swift:29:18:29:21 | x | test.swift:30:15:30:15 | x | provenance | |
Expand Down Expand Up @@ -964,6 +965,7 @@ nodes
| test.swift:7:15:7:15 | t1 | semmle.label | t1 |
| test.swift:9:15:9:15 | t1 | semmle.label | t1 |
| test.swift:10:15:10:15 | t2 | semmle.label | t2 |
| test.swift:15:15:15:15 | t2 | semmle.label | t2 |
| test.swift:25:20:25:27 | call to source() | semmle.label | call to source() |
| test.swift:26:26:26:33 | call to source() | semmle.label | call to source() |
| test.swift:29:18:29:21 | x | semmle.label | x |
Expand Down Expand Up @@ -1706,6 +1708,7 @@ subpaths
| test.swift:7:15:7:15 | t1 | test.swift:6:19:6:26 | call to source() | test.swift:7:15:7:15 | t1 | result |
| test.swift:9:15:9:15 | t1 | test.swift:6:19:6:26 | call to source() | test.swift:9:15:9:15 | t1 | result |
| test.swift:10:15:10:15 | t2 | test.swift:6:19:6:26 | call to source() | test.swift:10:15:10:15 | t2 | result |
| test.swift:15:15:15:15 | t2 | test.swift:6:19:6:26 | call to source() | test.swift:15:15:15:15 | t2 | result |
| test.swift:30:15:30:15 | x | test.swift:25:20:25:27 | call to source() | test.swift:30:15:30:15 | x | result |
| test.swift:31:15:31:15 | y | test.swift:26:26:26:33 | call to source() | test.swift:31:15:31:15 | y | result |
| test.swift:39:15:39:29 | call to callee_source() | test.swift:35:12:35:19 | call to source() | test.swift:39:15:39:29 | call to callee_source() | result |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,13 @@
| test.swift:7:15:7:15 | [post] t1 | test.swift:8:10:8:10 | t1 |
| test.swift:7:15:7:15 | t1 | test.swift:8:10:8:10 | t1 |
| test.swift:8:5:8:10 | SSA def(t2) | test.swift:10:15:10:15 | t2 |
| test.swift:8:5:8:10 | SSA def(t2) | test.swift:15:5:15:5 | SSA phi(t2) |
| test.swift:8:10:8:10 | t1 | test.swift:8:5:8:10 | SSA def(t2) |
| test.swift:8:10:8:10 | t1 | test.swift:9:15:9:15 | t1 |
| test.swift:9:15:9:15 | [post] t1 | test.swift:11:8:11:8 | t1 |
| test.swift:9:15:9:15 | t1 | test.swift:11:8:11:8 | t1 |
| test.swift:12:9:12:14 | SSA def(t2) | test.swift:13:19:13:19 | t2 |
| test.swift:12:9:12:14 | SSA def(t2) | test.swift:15:5:15:5 | SSA phi(t2) |
| test.swift:12:14:12:14 | 0 | test.swift:12:9:12:14 | SSA def(t2) |
| test.swift:15:5:15:5 | SSA phi(t2) | test.swift:15:15:15:15 | t2 |
| test.swift:17:5:17:10 | SSA def(t1) | test.swift:21:15:21:15 | t1 |
Expand Down
2 changes: 1 addition & 1 deletion swift/ql/test/library-tests/dataflow/dataflow/test.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func intraprocedural_with_local_flow() -> Void {
t2 = 0
sink(arg: t2)
}
sink(arg: t2) // $ MISSING: flow=6
sink(arg: t2) // $ flow=6

t1 = 0;
while(false) {
Expand Down
Loading