Skip to content

Commit e04075b

Browse files
authored
Merge pull request #19177 from aschackmull/swift/ssa-useuse
Swift: Update SSA to reference the new use-use predicates.
2 parents bb15f30 + e1ef56b commit e04075b

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

swift/ql/lib/codeql/swift/dataflow/Ssa.qll

+6-7
Original file line numberDiff line numberDiff line change
@@ -151,25 +151,24 @@ module Ssa {
151151

152152
cached
153153
ControlFlowNode getAFirstRead() {
154-
exists(SsaInput::BasicBlock bb1, int i1, SsaInput::BasicBlock bb2, int i2 |
155-
this.definesAt(_, bb1, i1) and
156-
SsaImpl::adjacentDefRead(this, bb1, i1, bb2, i2) and
157-
result = bb2.getNode(i2)
154+
exists(SsaInput::BasicBlock bb, int i |
155+
SsaImpl::firstUse(this, bb, i, true) and
156+
result = bb.getNode(i)
158157
)
159158
}
160159

161160
cached
162161
predicate adjacentReadPair(ControlFlowNode read1, ControlFlowNode read2) {
162+
read1 = this.getARead() and
163163
exists(SsaInput::BasicBlock bb1, int i1, SsaInput::BasicBlock bb2, int i2 |
164164
read1 = bb1.getNode(i1) and
165-
SsaInput::variableRead(bb1, i1, _, true) and
166-
SsaImpl::adjacentDefRead(this, bb1, i1, bb2, i2) and
165+
SsaImpl::adjacentUseUse(bb1, i1, bb2, i2, _, true) and
167166
read2 = bb2.getNode(i2)
168167
)
169168
}
170169

171170
cached
172-
predicate lastRefRedef(SsaInput::BasicBlock bb, int i, Definition next) {
171+
deprecated predicate lastRefRedef(SsaInput::BasicBlock bb, int i, Definition next) {
173172
SsaImpl::lastRefRedef(this, bb, i, next)
174173
}
175174
}

swift/ql/lib/codeql/swift/dataflow/internal/DataFlowPrivate.qll

+2-4
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,8 @@ private class CaptureNodeImpl extends CaptureNode, NodeImpl {
111111
}
112112

113113
private predicate localFlowSsaInput(Node nodeFrom, Ssa::Definition def, Ssa::Definition next) {
114-
exists(BasicBlock bb, int i | def.lastRefRedef(bb, i, next) |
115-
def.definesAt(_, bb, i) and
116-
def = nodeFrom.asDefinition()
117-
)
114+
next.(Ssa::PhiDefinition).getAPhiInput() = def and
115+
def = nodeFrom.asDefinition()
118116
}
119117

120118
/** A collection of cached types and predicates to be evaluated in the same stage. */

swift/ql/test/library-tests/dataflow/dataflow/DataFlow.expected

+3
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ edges
172172
| test.swift:6:19:6:26 | call to source() | test.swift:7:15:7:15 | t1 | provenance | |
173173
| test.swift:6:19:6:26 | call to source() | test.swift:9:15:9:15 | t1 | provenance | |
174174
| test.swift:6:19:6:26 | call to source() | test.swift:10:15:10:15 | t2 | provenance | |
175+
| test.swift:6:19:6:26 | call to source() | test.swift:15:15:15:15 | t2 | provenance | |
175176
| test.swift:25:20:25:27 | call to source() | test.swift:29:18:29:21 | x | provenance | |
176177
| test.swift:26:26:26:33 | call to source() | test.swift:29:26:29:29 | y | provenance | |
177178
| test.swift:29:18:29:21 | x | test.swift:30:15:30:15 | x | provenance | |
@@ -964,6 +965,7 @@ nodes
964965
| test.swift:7:15:7:15 | t1 | semmle.label | t1 |
965966
| test.swift:9:15:9:15 | t1 | semmle.label | t1 |
966967
| test.swift:10:15:10:15 | t2 | semmle.label | t2 |
968+
| test.swift:15:15:15:15 | t2 | semmle.label | t2 |
967969
| test.swift:25:20:25:27 | call to source() | semmle.label | call to source() |
968970
| test.swift:26:26:26:33 | call to source() | semmle.label | call to source() |
969971
| test.swift:29:18:29:21 | x | semmle.label | x |
@@ -1706,6 +1708,7 @@ subpaths
17061708
| test.swift:7:15:7:15 | t1 | test.swift:6:19:6:26 | call to source() | test.swift:7:15:7:15 | t1 | result |
17071709
| test.swift:9:15:9:15 | t1 | test.swift:6:19:6:26 | call to source() | test.swift:9:15:9:15 | t1 | result |
17081710
| test.swift:10:15:10:15 | t2 | test.swift:6:19:6:26 | call to source() | test.swift:10:15:10:15 | t2 | result |
1711+
| test.swift:15:15:15:15 | t2 | test.swift:6:19:6:26 | call to source() | test.swift:15:15:15:15 | t2 | result |
17091712
| test.swift:30:15:30:15 | x | test.swift:25:20:25:27 | call to source() | test.swift:30:15:30:15 | x | result |
17101713
| test.swift:31:15:31:15 | y | test.swift:26:26:26:33 | call to source() | test.swift:31:15:31:15 | y | result |
17111714
| 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 |

swift/ql/test/library-tests/dataflow/dataflow/LocalFlow.expected

+2
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,13 @@
250250
| test.swift:7:15:7:15 | [post] t1 | test.swift:8:10:8:10 | t1 |
251251
| test.swift:7:15:7:15 | t1 | test.swift:8:10:8:10 | t1 |
252252
| test.swift:8:5:8:10 | SSA def(t2) | test.swift:10:15:10:15 | t2 |
253+
| test.swift:8:5:8:10 | SSA def(t2) | test.swift:15:5:15:5 | SSA phi(t2) |
253254
| test.swift:8:10:8:10 | t1 | test.swift:8:5:8:10 | SSA def(t2) |
254255
| test.swift:8:10:8:10 | t1 | test.swift:9:15:9:15 | t1 |
255256
| test.swift:9:15:9:15 | [post] t1 | test.swift:11:8:11:8 | t1 |
256257
| test.swift:9:15:9:15 | t1 | test.swift:11:8:11:8 | t1 |
257258
| test.swift:12:9:12:14 | SSA def(t2) | test.swift:13:19:13:19 | t2 |
259+
| test.swift:12:9:12:14 | SSA def(t2) | test.swift:15:5:15:5 | SSA phi(t2) |
258260
| test.swift:12:14:12:14 | 0 | test.swift:12:9:12:14 | SSA def(t2) |
259261
| test.swift:15:5:15:5 | SSA phi(t2) | test.swift:15:15:15:15 | t2 |
260262
| test.swift:17:5:17:10 | SSA def(t1) | test.swift:21:15:21:15 | t1 |

swift/ql/test/library-tests/dataflow/dataflow/test.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func intraprocedural_with_local_flow() -> Void {
1212
t2 = 0
1313
sink(arg: t2)
1414
}
15-
sink(arg: t2) // $ MISSING: flow=6
15+
sink(arg: t2) // $ flow=6
1616

1717
t1 = 0;
1818
while(false) {

0 commit comments

Comments
 (0)