Skip to content

Commit a1639c4

Browse files
authored
Merge pull request github#11762 from erik-krogh/fixParent
QL: fix `getAnnotation()` for new-type branches with parameters
2 parents c9258ef + ab9855e commit a1639c4

File tree

3 files changed

+89
-18
lines changed

3 files changed

+89
-18
lines changed

ql/ql/src/codeql_ql/ast/Ast.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ class AstNode extends TAstNode {
9090
/** Gets an annotation of this AST node. */
9191
Annotation getAnAnnotation() {
9292
not this instanceof Annotation and // avoid cyclic parent-child relationship
93-
toQL(this).getParent() = pragma[only_bind_out](toQL(result)).getParent()
93+
toQL(this).getParent() = pragma[only_bind_out](toQL(result)).getParent() and
94+
// special case that is handled in `NewTypeBranch`
95+
not any(QL::DatatypeBranch branch) = pragma[only_bind_out](toQL(result)).getParent()
9496
}
9597

9698
/**

ql/ql/test/printAst/Foo.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,8 @@ predicate calls(Foo f) {
2929
newtype TPathNode =
3030
pragma[assume_small_delta]
3131
TPathNodeMid()
32+
33+
private newtype TPathNode2 =
34+
pragma[assume_small_delta]
35+
TPathNodeMid2(boolean foo) { foo = true } or
36+
TPathNodeSink(string bar) { bar = "bar" }

ql/ql/test/printAst/printAst.expected

Lines changed: 81 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
nodes
22
| Foo.qll:1:1:1:17 | Import | semmle.label | [Import] Import |
33
| Foo.qll:1:1:1:17 | Import | semmle.order | 1 |
4-
| Foo.qll:1:1:31:17 | TopLevel | semmle.label | [TopLevel] TopLevel |
5-
| Foo.qll:1:1:31:17 | TopLevel | semmle.order | 1 |
4+
| Foo.qll:1:1:36:44 | TopLevel | semmle.label | [TopLevel] TopLevel |
5+
| Foo.qll:1:1:36:44 | TopLevel | semmle.order | 1 |
66
| Foo.qll:1:8:1:17 | javascript | semmle.label | [ModuleExpr] javascript |
77
| Foo.qll:1:8:1:17 | javascript | semmle.order | 3 |
88
| Foo.qll:3:7:3:9 | Class Foo | semmle.label | [Class] Class Foo |
@@ -161,6 +161,38 @@ nodes
161161
| Foo.qll:30:10:30:27 | assume_small_delta | semmle.order | 80 |
162162
| Foo.qll:31:3:31:14 | NewTypeBranch TPathNodeMid | semmle.label | [NewTypeBranch] NewTypeBranch TPathNodeMid |
163163
| Foo.qll:31:3:31:14 | NewTypeBranch TPathNodeMid | semmle.order | 81 |
164+
| Foo.qll:33:1:33:7 | annotation | semmle.label | [Annotation] annotation |
165+
| Foo.qll:33:1:33:7 | annotation | semmle.order | 82 |
166+
| Foo.qll:33:17:33:26 | NewType TPathNode2 | semmle.label | [NewType] NewType TPathNode2 |
167+
| Foo.qll:33:17:33:26 | NewType TPathNode2 | semmle.order | 83 |
168+
| Foo.qll:34:3:34:28 | annotation | semmle.label | [Annotation] annotation |
169+
| Foo.qll:34:3:34:28 | annotation | semmle.order | 84 |
170+
| Foo.qll:34:10:34:27 | assume_small_delta | semmle.label | [AnnotationArg] assume_small_delta |
171+
| Foo.qll:34:10:34:27 | assume_small_delta | semmle.order | 85 |
172+
| Foo.qll:35:3:35:15 | NewTypeBranch TPathNodeMid2 | semmle.label | [NewTypeBranch] NewTypeBranch TPathNodeMid2 |
173+
| Foo.qll:35:3:35:15 | NewTypeBranch TPathNodeMid2 | semmle.order | 86 |
174+
| Foo.qll:35:17:35:23 | TypeExpr | semmle.label | [TypeExpr] TypeExpr |
175+
| Foo.qll:35:17:35:23 | TypeExpr | semmle.order | 87 |
176+
| Foo.qll:35:17:35:27 | foo | semmle.label | [VarDecl] foo |
177+
| Foo.qll:35:17:35:27 | foo | semmle.order | 87 |
178+
| Foo.qll:35:32:35:34 | foo | semmle.label | [VarAccess] foo |
179+
| Foo.qll:35:32:35:34 | foo | semmle.order | 89 |
180+
| Foo.qll:35:32:35:41 | ComparisonFormula | semmle.label | [ComparisonFormula] ComparisonFormula |
181+
| Foo.qll:35:32:35:41 | ComparisonFormula | semmle.order | 89 |
182+
| Foo.qll:35:38:35:41 | Boolean | semmle.label | [Boolean] Boolean |
183+
| Foo.qll:35:38:35:41 | Boolean | semmle.order | 91 |
184+
| Foo.qll:36:3:36:15 | NewTypeBranch TPathNodeSink | semmle.label | [NewTypeBranch] NewTypeBranch TPathNodeSink |
185+
| Foo.qll:36:3:36:15 | NewTypeBranch TPathNodeSink | semmle.order | 92 |
186+
| Foo.qll:36:17:36:22 | TypeExpr | semmle.label | [TypeExpr] TypeExpr |
187+
| Foo.qll:36:17:36:22 | TypeExpr | semmle.order | 93 |
188+
| Foo.qll:36:17:36:26 | bar | semmle.label | [VarDecl] bar |
189+
| Foo.qll:36:17:36:26 | bar | semmle.order | 93 |
190+
| Foo.qll:36:31:36:33 | bar | semmle.label | [VarAccess] bar |
191+
| Foo.qll:36:31:36:33 | bar | semmle.order | 95 |
192+
| Foo.qll:36:31:36:41 | ComparisonFormula | semmle.label | [ComparisonFormula] ComparisonFormula |
193+
| Foo.qll:36:31:36:41 | ComparisonFormula | semmle.order | 95 |
194+
| Foo.qll:36:37:36:41 | String | semmle.label | [String] String |
195+
| Foo.qll:36:37:36:41 | String | semmle.order | 97 |
164196
| file://:0:0:0:0 | abs | semmle.label | [BuiltinPredicate] abs |
165197
| file://:0:0:0:0 | abs | semmle.label | [BuiltinPredicate] abs |
166198
| file://:0:0:0:0 | acos | semmle.label | [BuiltinPredicate] acos |
@@ -243,24 +275,26 @@ nodes
243275
| file://:0:0:0:0 | trim | semmle.label | [BuiltinPredicate] trim |
244276
| file://:0:0:0:0 | ulp | semmle.label | [BuiltinPredicate] ulp |
245277
| printAst.ql:1:1:1:28 | Import | semmle.label | [Import] Import |
246-
| printAst.ql:1:1:1:28 | Import | semmle.order | 82 |
278+
| printAst.ql:1:1:1:28 | Import | semmle.order | 98 |
247279
| printAst.ql:1:1:1:29 | TopLevel | semmle.label | [TopLevel] TopLevel |
248-
| printAst.ql:1:1:1:29 | TopLevel | semmle.order | 82 |
280+
| printAst.ql:1:1:1:29 | TopLevel | semmle.order | 98 |
249281
| printAst.ql:1:18:1:28 | printAstAst | semmle.label | [ModuleExpr] printAstAst |
250-
| printAst.ql:1:18:1:28 | printAstAst | semmle.order | 84 |
282+
| printAst.ql:1:18:1:28 | printAstAst | semmle.order | 100 |
251283
edges
252284
| Foo.qll:1:1:1:17 | Import | Foo.qll:1:8:1:17 | javascript | semmle.label | getModuleExpr() |
253285
| Foo.qll:1:1:1:17 | Import | Foo.qll:1:8:1:17 | javascript | semmle.order | 3 |
254-
| Foo.qll:1:1:31:17 | TopLevel | Foo.qll:1:1:1:17 | Import | semmle.label | getAnImport() |
255-
| Foo.qll:1:1:31:17 | TopLevel | Foo.qll:1:1:1:17 | Import | semmle.order | 1 |
256-
| Foo.qll:1:1:31:17 | TopLevel | Foo.qll:3:7:3:9 | Class Foo | semmle.label | getAClass() |
257-
| Foo.qll:1:1:31:17 | TopLevel | Foo.qll:3:7:3:9 | Class Foo | semmle.order | 4 |
258-
| Foo.qll:1:1:31:17 | TopLevel | Foo.qll:9:17:9:19 | ClasslessPredicate foo | semmle.label | getAPredicate() |
259-
| Foo.qll:1:1:31:17 | TopLevel | Foo.qll:9:17:9:19 | ClasslessPredicate foo | semmle.order | 16 |
260-
| Foo.qll:1:1:31:17 | TopLevel | Foo.qll:13:11:13:15 | ClasslessPredicate calls | semmle.label | getAPredicate() |
261-
| Foo.qll:1:1:31:17 | TopLevel | Foo.qll:13:11:13:15 | ClasslessPredicate calls | semmle.order | 32 |
262-
| Foo.qll:1:1:31:17 | TopLevel | Foo.qll:29:9:29:17 | NewType TPathNode | semmle.label | getANewType() |
263-
| Foo.qll:1:1:31:17 | TopLevel | Foo.qll:29:9:29:17 | NewType TPathNode | semmle.order | 78 |
286+
| Foo.qll:1:1:36:44 | TopLevel | Foo.qll:1:1:1:17 | Import | semmle.label | getAnImport() |
287+
| Foo.qll:1:1:36:44 | TopLevel | Foo.qll:1:1:1:17 | Import | semmle.order | 1 |
288+
| Foo.qll:1:1:36:44 | TopLevel | Foo.qll:3:7:3:9 | Class Foo | semmle.label | getAClass() |
289+
| Foo.qll:1:1:36:44 | TopLevel | Foo.qll:3:7:3:9 | Class Foo | semmle.order | 4 |
290+
| Foo.qll:1:1:36:44 | TopLevel | Foo.qll:9:17:9:19 | ClasslessPredicate foo | semmle.label | getAPredicate() |
291+
| Foo.qll:1:1:36:44 | TopLevel | Foo.qll:9:17:9:19 | ClasslessPredicate foo | semmle.order | 16 |
292+
| Foo.qll:1:1:36:44 | TopLevel | Foo.qll:13:11:13:15 | ClasslessPredicate calls | semmle.label | getAPredicate() |
293+
| Foo.qll:1:1:36:44 | TopLevel | Foo.qll:13:11:13:15 | ClasslessPredicate calls | semmle.order | 32 |
294+
| Foo.qll:1:1:36:44 | TopLevel | Foo.qll:29:9:29:17 | NewType TPathNode | semmle.label | getANewType() |
295+
| Foo.qll:1:1:36:44 | TopLevel | Foo.qll:29:9:29:17 | NewType TPathNode | semmle.order | 78 |
296+
| Foo.qll:1:1:36:44 | TopLevel | Foo.qll:33:17:33:26 | NewType TPathNode2 | semmle.label | getANewType() |
297+
| Foo.qll:1:1:36:44 | TopLevel | Foo.qll:33:17:33:26 | NewType TPathNode2 | semmle.order | 83 |
264298
| Foo.qll:3:7:3:9 | Class Foo | Foo.qll:3:19:3:22 | TypeExpr | semmle.label | getASuperType() |
265299
| Foo.qll:3:7:3:9 | Class Foo | Foo.qll:3:19:3:22 | TypeExpr | semmle.order | 5 |
266300
| Foo.qll:3:7:3:9 | Class Foo | Foo.qll:4:3:4:17 | CharPred Foo | semmle.label | getCharPred() |
@@ -409,9 +443,39 @@ edges
409443
| Foo.qll:30:3:30:28 | annotation | Foo.qll:30:10:30:27 | assume_small_delta | semmle.order | 80 |
410444
| Foo.qll:31:3:31:14 | NewTypeBranch TPathNodeMid | Foo.qll:30:3:30:28 | annotation | semmle.label | getAnAnnotation() |
411445
| Foo.qll:31:3:31:14 | NewTypeBranch TPathNodeMid | Foo.qll:30:3:30:28 | annotation | semmle.order | 79 |
446+
| Foo.qll:33:17:33:26 | NewType TPathNode2 | Foo.qll:33:1:33:7 | annotation | semmle.label | getAnAnnotation() |
447+
| Foo.qll:33:17:33:26 | NewType TPathNode2 | Foo.qll:33:1:33:7 | annotation | semmle.order | 82 |
448+
| Foo.qll:33:17:33:26 | NewType TPathNode2 | Foo.qll:35:3:35:15 | NewTypeBranch TPathNodeMid2 | semmle.label | getABranch() |
449+
| Foo.qll:33:17:33:26 | NewType TPathNode2 | Foo.qll:35:3:35:15 | NewTypeBranch TPathNodeMid2 | semmle.order | 86 |
450+
| Foo.qll:33:17:33:26 | NewType TPathNode2 | Foo.qll:36:3:36:15 | NewTypeBranch TPathNodeSink | semmle.label | getABranch() |
451+
| Foo.qll:33:17:33:26 | NewType TPathNode2 | Foo.qll:36:3:36:15 | NewTypeBranch TPathNodeSink | semmle.order | 92 |
452+
| Foo.qll:34:3:34:28 | annotation | Foo.qll:34:10:34:27 | assume_small_delta | semmle.label | getArgs(_) |
453+
| Foo.qll:34:3:34:28 | annotation | Foo.qll:34:10:34:27 | assume_small_delta | semmle.order | 85 |
454+
| Foo.qll:35:3:35:15 | NewTypeBranch TPathNodeMid2 | Foo.qll:34:3:34:28 | annotation | semmle.label | getAnAnnotation() |
455+
| Foo.qll:35:3:35:15 | NewTypeBranch TPathNodeMid2 | Foo.qll:34:3:34:28 | annotation | semmle.order | 84 |
456+
| Foo.qll:35:3:35:15 | NewTypeBranch TPathNodeMid2 | Foo.qll:35:17:35:27 | foo | semmle.label | getField(_) |
457+
| Foo.qll:35:3:35:15 | NewTypeBranch TPathNodeMid2 | Foo.qll:35:17:35:27 | foo | semmle.order | 87 |
458+
| Foo.qll:35:3:35:15 | NewTypeBranch TPathNodeMid2 | Foo.qll:35:32:35:41 | ComparisonFormula | semmle.label | getBody() |
459+
| Foo.qll:35:3:35:15 | NewTypeBranch TPathNodeMid2 | Foo.qll:35:32:35:41 | ComparisonFormula | semmle.order | 89 |
460+
| Foo.qll:35:17:35:27 | foo | Foo.qll:35:17:35:23 | TypeExpr | semmle.label | getTypeExpr() |
461+
| Foo.qll:35:17:35:27 | foo | Foo.qll:35:17:35:23 | TypeExpr | semmle.order | 87 |
462+
| Foo.qll:35:32:35:41 | ComparisonFormula | Foo.qll:35:32:35:34 | foo | semmle.label | getLeftOperand() |
463+
| Foo.qll:35:32:35:41 | ComparisonFormula | Foo.qll:35:32:35:34 | foo | semmle.order | 89 |
464+
| Foo.qll:35:32:35:41 | ComparisonFormula | Foo.qll:35:38:35:41 | Boolean | semmle.label | getRightOperand() |
465+
| Foo.qll:35:32:35:41 | ComparisonFormula | Foo.qll:35:38:35:41 | Boolean | semmle.order | 91 |
466+
| Foo.qll:36:3:36:15 | NewTypeBranch TPathNodeSink | Foo.qll:36:17:36:26 | bar | semmle.label | getField(_) |
467+
| Foo.qll:36:3:36:15 | NewTypeBranch TPathNodeSink | Foo.qll:36:17:36:26 | bar | semmle.order | 93 |
468+
| Foo.qll:36:3:36:15 | NewTypeBranch TPathNodeSink | Foo.qll:36:31:36:41 | ComparisonFormula | semmle.label | getBody() |
469+
| Foo.qll:36:3:36:15 | NewTypeBranch TPathNodeSink | Foo.qll:36:31:36:41 | ComparisonFormula | semmle.order | 95 |
470+
| Foo.qll:36:17:36:26 | bar | Foo.qll:36:17:36:22 | TypeExpr | semmle.label | getTypeExpr() |
471+
| Foo.qll:36:17:36:26 | bar | Foo.qll:36:17:36:22 | TypeExpr | semmle.order | 93 |
472+
| Foo.qll:36:31:36:41 | ComparisonFormula | Foo.qll:36:31:36:33 | bar | semmle.label | getLeftOperand() |
473+
| Foo.qll:36:31:36:41 | ComparisonFormula | Foo.qll:36:31:36:33 | bar | semmle.order | 95 |
474+
| Foo.qll:36:31:36:41 | ComparisonFormula | Foo.qll:36:37:36:41 | String | semmle.label | getRightOperand() |
475+
| Foo.qll:36:31:36:41 | ComparisonFormula | Foo.qll:36:37:36:41 | String | semmle.order | 97 |
412476
| printAst.ql:1:1:1:28 | Import | printAst.ql:1:18:1:28 | printAstAst | semmle.label | getModuleExpr() |
413-
| printAst.ql:1:1:1:28 | Import | printAst.ql:1:18:1:28 | printAstAst | semmle.order | 84 |
477+
| printAst.ql:1:1:1:28 | Import | printAst.ql:1:18:1:28 | printAstAst | semmle.order | 100 |
414478
| printAst.ql:1:1:1:29 | TopLevel | printAst.ql:1:1:1:28 | Import | semmle.label | getAnImport() |
415-
| printAst.ql:1:1:1:29 | TopLevel | printAst.ql:1:1:1:28 | Import | semmle.order | 82 |
479+
| printAst.ql:1:1:1:29 | TopLevel | printAst.ql:1:1:1:28 | Import | semmle.order | 98 |
416480
graphProperties
417481
| semmle.graphKind | tree |

0 commit comments

Comments
 (0)