Skip to content

Commit 9f260cf

Browse files
committed
QL4QL: Discard predicates are always alive
1 parent 9de3617 commit 9f260cf

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

ql/ql/src/codeql_ql/style/DeadCodeQuery.qll

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ private AstNode queryPredicate() {
3939
result = queryPredicate().getAChild()
4040
}
4141

42+
private AstNode discardPredicate() {
43+
result.(Predicate).getAnAnnotation() instanceof OverlayDiscardEntity
44+
}
45+
4246
AstNode hackyShouldBeTreatedAsAlive() {
4347
// Stages from the shared DataFlow impl are copy-pasted, so predicates that are dead in one stage are not dead in another.
4448
result = any(Module mod | mod.getName().matches("Stage%")).getAMember().(ClasslessPredicate) and
@@ -58,7 +62,7 @@ AstNode hackyShouldBeTreatedAsAlive() {
5862
*/
5963
private AstNode alive() {
6064
//
61-
// The 4 base cases.
65+
// The 5 base cases.
6266
//
6367
// 1) everything that can be imported.
6468
result = publicApi()
@@ -73,6 +77,9 @@ private AstNode alive() {
7377
// 4) Things that aren't really alive, but that this query treats as live.
7478
result = hackyShouldBeTreatedAsAlive()
7579
or
80+
// 5) discard predicates
81+
result = discardPredicate()
82+
or
7683
result instanceof TopLevel // toplevel is always alive.
7784
or
7885
// recursive cases

0 commit comments

Comments
 (0)