Content-Length: 2988 | pFad | http://github.com/github/codeql/pull/20013.diff

thub.com 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 } diff --git a/ql/ql/src/codeql_ql/style/DeadCodeQuery.qll b/ql/ql/src/codeql_ql/style/DeadCodeQuery.qll index 211084f29158..4098511e9067 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 6 base cases. // // 1) everything that can be imported. result = publicApi() @@ -73,7 +77,11 @@ private AstNode alive() { // 4) Things that aren't really alive, but that this query treats as live. result = hackyShouldBeTreatedAsAlive() or - result instanceof TopLevel // toplevel is always alive. + // 5) discard predicates + result = discardPredicate() + or + // 6) toplevel is always alive. + result instanceof TopLevel or // recursive cases result = aliveStep(alive()) 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() }








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/github/codeql/pull/20013.diff

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy