Skip to content

Commit bd86ffb

Browse files
authored
fix the arity of predicate aliases
1 parent 8dc3948 commit bd86ffb

4 files changed

Lines changed: 29 additions & 1 deletion

File tree

ql/src/codeql_ql/ast/Ast.qll

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,14 @@ class Predicate extends TPredicate, AstNode {
154154
/**
155155
* Gets the number of parameters.
156156
*/
157-
int getArity() { result = count(getParameter(_)) }
157+
int getArity() {
158+
not this.(ClasslessPredicate).getAlias() instanceof PredicateExpr and
159+
result = count(getParameter(_))
160+
or
161+
exists(PredicateExpr alias | alias = this.(ClasslessPredicate).getAlias() |
162+
result = alias.getArity()
163+
)
164+
}
158165

159166
/**
160167
* Gets the return type (if any) of the predicate.

ql/src/codeql_ql/ast/internal/Predicate.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ module PredConsistency {
240240
query predicate noResolveCall(Call c) {
241241
not resolveCall(c, _) and
242242
not c instanceof NoneCall and
243+
not c instanceof AnyCall and
243244
not c.getLocation().getFile().getAbsolutePath().regexpMatch(".*/(test|examples)/.*")
244245
}
245246

ql/test/callgraph/Foo.qll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,19 @@ class Sub extends Foo {
1515
}
1616

1717
query predicate test2() { any(Foo f).bar() }
18+
19+
module Aliases {
20+
predicate myThing2(int i, int j) { i = 2 and j = 3 }
21+
22+
predicate myThing0() { any() }
23+
24+
predicate alias0 = myThing0/0;
25+
26+
predicate alias2 = myThing2/2;
27+
28+
query predicate test3() {
29+
alias2(3, 4) // doesn't work.
30+
or
31+
alias0() // <- works
32+
}
33+
}

ql/test/callgraph/callgraph.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22
| Foo.qll:10:21:10:25 | PredicateCall | Foo.qll:8:3:8:28 | ClassPredicate |
33
| Foo.qll:14:30:14:40 | MemberCall | Foo.qll:10:3:10:27 | ClassPredicate |
44
| Foo.qll:17:27:17:42 | MemberCall | Foo.qll:8:3:8:28 | ClassPredicate |
5+
| Foo.qll:29:5:29:16 | PredicateCall | Foo.qll:20:3:20:54 | myThing2 |
6+
| Foo.qll:29:5:29:16 | PredicateCall | Foo.qll:26:3:26:32 | alias2 |
7+
| Foo.qll:31:5:31:12 | PredicateCall | Foo.qll:22:3:22:32 | myThing0 |
8+
| Foo.qll:31:5:31:12 | PredicateCall | Foo.qll:24:3:24:32 | alias0 |

0 commit comments

Comments
 (0)