Skip to content

Commit 1265c3f

Browse files
committed
QL: Merge branch 'main' into extractor-pack
2 parents 54b7fa3 + fed3d80 commit 1265c3f

6 files changed

Lines changed: 59 additions & 11 deletions

File tree

.github/workflows/build.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ jobs:
1414
strategy:
1515
fail-fast: false
1616
matrix:
17-
os: [ubuntu-latest, macos-latest, windows-latest]
17+
os: [ubuntu-latest, macos-latest]
18+
#os: [ubuntu-latest, macos-latest, windows-latest]
1819

1920
runs-on: ${{ matrix.os }}
2021

@@ -73,21 +74,20 @@ jobs:
7374
with:
7475
name: extractor-ubuntu-latest
7576
path: linux64
76-
- uses: actions/download-artifact@v2
77-
with:
78-
name: extractor-windows-latest
79-
path: win64
77+
# - uses: actions/download-artifact@v2
78+
# with:
79+
# name: extractor-windows-latest
80+
# path: win64
8081
- uses: actions/download-artifact@v2
8182
with:
8283
name: extractor-macos-latest
8384
path: osx64
8485
- run: |
8586
mkdir -p ql
8687
cp -r codeql-extractor.yml tools ql/src/ql.dbscheme.stats ql/
87-
mkdir -p ql/tools/{linux64,osx64,win64}
88+
mkdir -p ql/tools/{linux64,osx64}
8889
cp linux64/ql-extractor ql/tools/linux64/extractor
8990
cp osx64/ql-extractor ql/tools/osx64/extractor
90-
cp win64/ql-extractor.exe ql/tools/win64/extractor.exe
9191
chmod +x ql/tools/{linux64,osx64}/extractor
9292
zip -rq codeql-ql.zip ql
9393
- uses: actions/upload-artifact@v2

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ extractor-pack
55
ql/test/**/*.testproj
66
ql/test/**/*.actual
77
ql/test/**/CONSISTENCY
8+
work

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Under development.
66

77
## Building the tools from source
88

9-
[Install Rust](https://www.rust-lang.org/tools/install), then run:
9+
[Install Rust](https://www.rust-lang.org/tools/install) (if using VSCode, you may also want the `rust-analyzer` extension), then run:
1010

1111
```bash
1212
cargo build --release

ql/src/codeql_ql/ast/Ast.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ class NewTypeBranch extends TNewTypeBranch, TypeDeclaration {
771771
* or a member call `foo.bar()`,
772772
* or a special call to `none()` or `any()`.
773773
*/
774-
class Call extends TCall, Expr {
774+
class Call extends TCall, Expr, Formula {
775775
/** Gets the `i`th argument of this call. */
776776
Expr getArgument(int i) {
777777
none() // overriden in sublcasses.
@@ -1014,7 +1014,7 @@ class Conjunction extends TConjunction, AstNode, Formula {
10141014
}
10151015

10161016
/** An `or` formula, with 2 or more operands. */
1017-
class Disjunction extends TDisjunction, AstNode {
1017+
class Disjunction extends TDisjunction, AstNode, Formula {
10181018
Generated::Disjunction disj;
10191019

10201020
Disjunction() { this = TDisjunction(disj) }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ predicate isBuiltinMember(string sig) {
4242
"string string.toLowerCase()", "string string.toUpperCase()", "string string.trim()",
4343
"int date.daysTo(date)", "int date.getDay()", "int date.getHours()", "int date.getMinutes()",
4444
"int date.getMonth()", "int date.getSeconds()", "int date.getYear()",
45-
"string date.toString()", "string date.toISO()"
45+
"string date.toString()", "string date.toISO()", "string int.toUnicode()"
4646
]
4747
}
4848

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* @name Suggest using non-extending subtype relationships.
3+
* @description Non-extending subtypes ("instanceof extensions") are generally preferrable to instanceof expressions in characteristic predicates.
4+
* @kind problem
5+
* @problem.severity warning
6+
* @id ql/suggest-instanceof-extension
7+
* @tags maintainability
8+
* @precision medium
9+
*/
10+
11+
import ql
12+
13+
InstanceOf instanceofInCharPred(Class c) {
14+
result = c.getCharPred().getBody()
15+
or
16+
exists(Conjunction conj |
17+
conj = c.getCharPred().getBody() and
18+
result = conj.getAnOperand()
19+
)
20+
}
21+
22+
predicate instanceofThisInCharPred(Class c, TypeExpr type) {
23+
exists(InstanceOf instanceOf |
24+
instanceOf = instanceofInCharPred(c) and
25+
instanceOf.getExpr() instanceof ThisAccess and
26+
type = instanceOf.getType()
27+
)
28+
}
29+
30+
predicate classWithInstanceofThis(Class c, TypeExpr type) {
31+
instanceofThisInCharPred(c, type) and
32+
exists(ClassPredicate classPred |
33+
classPred = c.getAClassPredicate() and
34+
exists(MemberCall call, InlineCast cast |
35+
call.getEnclosingPredicate() = classPred and
36+
cast = call.getBase() and
37+
cast.getBase() instanceof ThisAccess and
38+
cast.getTypeExpr().getResolvedType() = type.getResolvedType()
39+
)
40+
)
41+
}
42+
43+
from Class c, TypeExpr type, string message
44+
where
45+
classWithInstanceofThis(c, type) and
46+
message = "consider defining $@ as non-extending subtype of $@"
47+
select c, message, c, c.getName(), type, type.getResolvedType().getName()

0 commit comments

Comments
 (0)