Content-Length: 4906 | pFad | http://github.com/github/codeql/pull/20013.patch
thub.com
From 9de361703281555283238135c6d6d4ac0fe8646f Mon Sep 17 00:00:00 2001
From: Kasper Svendsen
Date: Thu, 10 Jul 2025 11:01:06 +0200
Subject: [PATCH 1/4] QL4QL: Add overlay[discard_entity] annotation
---
ql/ql/src/codeql_ql/ast/Ast.qll | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/ql/ql/src/codeql_ql/ast/Ast.qll b/ql/ql/src/codeql_ql/ast/Ast.qll
index 89bdf14d4b2a..325e2f54743c 100644
--- a/ql/ql/src/codeql_ql/ast/Ast.qll
+++ b/ql/ql/src/codeql_ql/ast/Ast.qll
@@ -2554,6 +2554,10 @@ private class LocalQArg extends AnnotationArg {
LocalQArg() { this.getValue() = "local?" }
}
+private class DiscardEntityArg extends AnnotationArg {
+ DiscardEntityArg() { this.getValue() = "discard_entity" }
+}
+
private class MonotonicAggregatesArg extends AnnotationArg {
MonotonicAggregatesArg() { this.getValue() = "monotonicAggregates" }
}
@@ -2641,6 +2645,15 @@ class OverlayLocalQ extends Annotation {
override string toString() { result = "overlay[local?]" }
}
+/** An `overlay[discard_entity]` annotation. */
+class OverlayDiscardEntity extends Annotation {
+ OverlayDiscardEntity() {
+ this.getName() = "overlay" and this.getArgs(0) instanceof DiscardEntityArg
+ }
+
+ override string toString() { result = "overlay[discard_entity]" }
+}
+
/** A `language[monotonicAggregates]` annotation. */
class MonotonicAggregates extends Annotation {
MonotonicAggregates() { this.getArgs(0) instanceof MonotonicAggregatesArg }
From 9f260cf72fa4236f3db1662d8de8a84408bc73eb Mon Sep 17 00:00:00 2001
From: Kasper Svendsen
Date: Thu, 10 Jul 2025 11:01:37 +0200
Subject: [PATCH 2/4] QL4QL: Discard predicates are always alive
---
ql/ql/src/codeql_ql/style/DeadCodeQuery.qll | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/ql/ql/src/codeql_ql/style/DeadCodeQuery.qll b/ql/ql/src/codeql_ql/style/DeadCodeQuery.qll
index 211084f29158..a5addc294cbb 100644
--- a/ql/ql/src/codeql_ql/style/DeadCodeQuery.qll
+++ b/ql/ql/src/codeql_ql/style/DeadCodeQuery.qll
@@ -39,6 +39,10 @@ private AstNode queryPredicate() {
result = queryPredicate().getAChild()
}
+private AstNode discardPredicate() {
+ result.(Predicate).getAnAnnotation() instanceof OverlayDiscardEntity
+}
+
AstNode hackyShouldBeTreatedAsAlive() {
// Stages from the shared DataFlow impl are copy-pasted, so predicates that are dead in one stage are not dead in another.
result = any(Module mod | mod.getName().matches("Stage%")).getAMember().(ClasslessPredicate) and
@@ -58,7 +62,7 @@ AstNode hackyShouldBeTreatedAsAlive() {
*/
private AstNode alive() {
//
- // The 4 base cases.
+ // The 5 base cases.
//
// 1) everything that can be imported.
result = publicApi()
@@ -73,6 +77,9 @@ private AstNode alive() {
// 4) Things that aren't really alive, but that this query treats as live.
result = hackyShouldBeTreatedAsAlive()
or
+ // 5) discard predicates
+ result = discardPredicate()
+ or
result instanceof TopLevel // toplevel is always alive.
or
// recursive cases
From 1723c6ed092c9ba857f0e508b4f82adea97a864b Mon Sep 17 00:00:00 2001
From: Kasper Svendsen
Date: Thu, 10 Jul 2025 11:06:49 +0200
Subject: [PATCH 3/4] QL4QL: Add discard predicate to dead code test
---
ql/ql/test/queries/style/DeadCode/Foo.qll | 3 +++
1 file changed, 3 insertions(+)
diff --git a/ql/ql/test/queries/style/DeadCode/Foo.qll b/ql/ql/test/queries/style/DeadCode/Foo.qll
index 5b13fd99ca93..a5b5b08e2a4a 100644
--- a/ql/ql/test/queries/style/DeadCode/Foo.qll
+++ b/ql/ql/test/queries/style/DeadCode/Foo.qll
@@ -66,3 +66,6 @@ private class CImpl1 extends AstNode { }
final class CPublic1 = CImpl1;
private class CImpl2 extends AstNode { }
+
+overlay[discard_entity]
+private predicate discard(@foo x) { any() }
From c7a3b6543ed53abe495f3da0d509da48a9995ebf Mon Sep 17 00:00:00 2001
From: Kasper Svendsen
Date: Thu, 10 Jul 2025 12:01:29 +0200
Subject: [PATCH 4/4] Address copilot comment
---
ql/ql/src/codeql_ql/style/DeadCodeQuery.qll | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/ql/ql/src/codeql_ql/style/DeadCodeQuery.qll b/ql/ql/src/codeql_ql/style/DeadCodeQuery.qll
index a5addc294cbb..4098511e9067 100644
--- a/ql/ql/src/codeql_ql/style/DeadCodeQuery.qll
+++ b/ql/ql/src/codeql_ql/style/DeadCodeQuery.qll
@@ -62,7 +62,7 @@ AstNode hackyShouldBeTreatedAsAlive() {
*/
private AstNode alive() {
//
- // The 5 base cases.
+ // The 6 base cases.
//
// 1) everything that can be imported.
result = publicApi()
@@ -80,7 +80,8 @@ private AstNode alive() {
// 5) discard predicates
result = discardPredicate()
or
- result instanceof TopLevel // toplevel is always alive.
+ // 6) toplevel is always alive.
+ result instanceof TopLevel
or
// recursive cases
result = aliveStep(alive())
--- a PPN by Garber Painting Akron. With Image Size Reduction included!Fetched URL: http://github.com/github/codeql/pull/20013.patch
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy