Skip to content

Commit 6ce7a56

Browse files
authored
Merge pull request #14190 from github/alexdenisov/await-inconsistencies
Swift: fix CFG for identity expressions (await, dot_self, parent)
2 parents 7e7852e + 743fd90 commit 6ce7a56

File tree

3 files changed

+11
-40
lines changed

3 files changed

+11
-40
lines changed

swift/ql/lib/codeql/swift/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ module Stmts {
125125
c instanceof SimpleCompletion
126126
}
127127

128-
predicate firstInner(ControlFlowElement first) { astFirst(ast.getFirstElement(), first) }
128+
predicate firstInner(ControlFlowElement first) {
129+
astFirst(ast.getFirstElement().getFullyUnresolved(), first)
130+
}
129131

130132
/** Gets the body of the i'th `defer` statement. */
131133
private BraceStmt getDeferStmtBody(int i) {
@@ -181,32 +183,32 @@ module Stmts {
181183

182184
predicate lastInner(ControlFlowElement last, Completion c) {
183185
// Normal exit and no defer statements
184-
astLast(ast.getLastElement(), last, c) and
186+
astLast(ast.getLastElement().getFullyUnresolved(), last, c) and
185187
not exists(this.getFirstDeferStmtBody()) and
186188
c instanceof NormalCompletion
187189
or
188190
// Normal exit from the last defer statement to be executed
189-
astLast(this.getLastDeferStmtBody(), last, c) and
191+
astLast(this.getLastDeferStmtBody().getFullyUnresolved(), last, c) and
190192
c instanceof NormalCompletion
191193
or
192194
// Abnormal exit without any defer statements
193195
not c instanceof NormalCompletion and
194-
astLast(ast.getAnElement(), last, c) and
196+
astLast(ast.getAnElement().getFullyUnresolved(), last, c) and
195197
not exists(this.getFirstDeferStmtBody())
196198
}
197199

198200
override predicate succ(ControlFlowElement pred, ControlFlowElement succ, Completion c) {
199201
// left-to-right evaluation of statements
200202
exists(int i |
201-
astLast(ast.getElement(i), pred, c) and
202-
astFirst(ast.getElement(i + 1), succ) and
203+
astLast(ast.getElement(i).getFullyUnresolved(), pred, c) and
204+
astFirst(ast.getElement(i + 1).getFullyUnresolved(), succ) and
203205
c instanceof NormalCompletion
204206
)
205207
or
206208
// Flow from last elements to the first defer statement to be executed
207209
c instanceof NormalCompletion and
208-
astLast(ast.getLastElement(), pred, c) and
209-
astFirst(this.getFirstDeferStmtBody(), succ)
210+
astLast(ast.getLastElement().getFullyUnresolved(), pred, c) and
211+
astFirst(this.getFirstDeferStmtBody().getFullyUnresolved(), succ)
210212
or
211213
// Flow from a defer statement to the next defer to be executed
212214
c instanceof NormalCompletion and
@@ -218,7 +220,7 @@ module Stmts {
218220
// Abnormal exit from an element to the first defer statement to be executed.
219221
not c instanceof NormalCompletion and
220222
exists(int i |
221-
astLast(ast.getElement(i), pred, c) and
223+
astLast(ast.getElement(i).getFullyUnresolved(), pred, c) and
222224
astFirst(this.getDeferStmtBodyAfterStmt(i), succ)
223225
)
224226
}

swift/ql/test/extractor-tests/generated/expr/MethodLookupExpr/CONSISTENCY/CfgConsistency.expected

Lines changed: 0 additions & 14 deletions
This file was deleted.

swift/ql/test/library-tests/elements/expr/methodlookup/CONSISTENCY/CfgConsistency.expected

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)