Skip to content

Commit 5de8934

Browse files
authored
Merge pull request github#13277 from github/redsun82/swift-consistency-accept
Swift: add consistency check and accept results for the moment
2 parents f5070bb + ac31209 commit 5de8934

File tree

54 files changed

+466
-39
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+466
-39
lines changed

swift/actions/run-ql-tests/action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ runs:
2626
--check-repeated-labels \
2727
--check-redefined-labels \
2828
--check-use-before-definition \
29+
--consistency-queries "${{ github.workspace }}/swift/ql/consistency-queries" \
2930
--compilation-cache "${{ steps.query-cache.outputs.cache-dir }}" \
3031
${{ inputs.flags }} \
3132
swift/ql/test
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import codeql.swift.printast.Consistency
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: newQuery
3+
---
4+
* Added two consistency queries for checking control flow and AST printing internals.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name: codeql/swift-consistency-queries
2+
groups: [swift, test, consistency-queries]
3+
dependencies:
4+
codeql/swift-all: ${workspace}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/** Provides a set of checks that the AST is actually a tree. */
2+
3+
private import codeql.swift.printast.PrintAstNode
4+
5+
/** Checks that no child has more than one parent. */
6+
query predicate doubleParents(
7+
PrintAstNode parent1, string label1, PrintAstNode parent2, string label2, PrintAstNode child
8+
) {
9+
parent1 != parent2 and
10+
parent1.hasChild(child, _, label1) and
11+
parent2.hasChild(child, _, label2)
12+
}
13+
14+
/** Checks that no two children share the same index. */
15+
query predicate doubleChildren(
16+
PrintAstNode parent, int index, string label1, PrintAstNode child1, string label2,
17+
PrintAstNode child2
18+
) {
19+
child1 != child2 and
20+
parent.hasChild(child1, index, label1) and
21+
parent.hasChild(child2, index, label2)
22+
}
23+
24+
/** Checks that no child is under different indexes. */
25+
query predicate doubleIndexes(
26+
PrintAstNode parent, int index1, string label1, int index2, string label2, PrintAstNode child
27+
) {
28+
index1 != index2 and
29+
parent.hasChild(child, index1, label1) and
30+
parent.hasChild(child, index2, label2)
31+
}
32+
33+
private predicate isChildOf(PrintAstNode parent, PrintAstNode child) {
34+
parent.hasChild(child, _, _)
35+
}
36+
37+
/** Checks that there is no back edge. */
38+
query predicate parentChildLoops(PrintAstNode parent, PrintAstNode child) {
39+
isChildOf(parent, child) and isChildOf*(child, parent)
40+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
deadEnd
2+
| file://:0:0:0:0 | ... = ... |
3+
| file://:0:0:0:0 | ... = ... |
4+
| file://:0:0:0:0 | ... = ... |
5+
| file://:0:0:0:0 | ... = ... |
6+
| file://:0:0:0:0 | ... = ... |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
deadEnd
2+
| file://:0:0:0:0 | ... = ... |
3+
| file://:0:0:0:0 | ... = ... |
4+
| unspecified.swift:12:20:12:21 | (...) |
5+
| unspecified.swift:25:9:28:9 | switch ErrorExpr { ... } |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
deadEnd
2+
| file://:0:0:0:0 | ... = ... |
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
multipleSuccessors
2+
| var_decls.swift:54:4:54:15 | call to X<T>.init(wrappedValue:) | successor | file://:0:0:0:0 | var ... = ... |
3+
| var_decls.swift:54:4:54:15 | call to X<T>.init(wrappedValue:) | successor | var_decls.swift:54:6:54:15 | var ... = ... |
4+
| var_decls.swift:55:4:55:29 | call to WrapperWithInit.init(wrappedValue:) | successor | file://:0:0:0:0 | var ... = ... |
5+
| var_decls.swift:55:4:55:29 | call to WrapperWithInit.init(wrappedValue:) | successor | var_decls.swift:55:20:55:29 | var ... = ... |
6+
| var_decls.swift:56:4:56:34 | call to WrapperWithProjected.init(wrappedValue:projectedValue:) | successor | file://:0:0:0:0 | var ... = ... |
7+
| var_decls.swift:56:4:56:34 | call to WrapperWithProjected.init(wrappedValue:projectedValue:) | successor | var_decls.swift:56:25:56:34 | var ... = ... |
8+
| var_decls.swift:57:4:57:41 | call to WrapperWithProjectedAndInit.init(wrappedValue:) | successor | file://:0:0:0:0 | var ... = ... |
9+
| var_decls.swift:57:4:57:41 | call to WrapperWithProjectedAndInit.init(wrappedValue:) | successor | var_decls.swift:57:32:57:41 | var ... = ... |
10+
deadEnd
11+
| file://:0:0:0:0 | var ... = ... |
12+
| file://:0:0:0:0 | var ... = ... |
13+
| file://:0:0:0:0 | var ... = ... |
14+
| file://:0:0:0:0 | var ... = ... |

0 commit comments

Comments
 (0)