From e1fc138670b3130da7b8e2bae52edf5e5e91d844 Mon Sep 17 00:00:00 2001 From: Kasper Svendsen Date: Tue, 24 Jun 2025 11:29:36 +0200 Subject: [PATCH] QL4QL: Extend ql/inline-overlay-caller --- ql/ql/src/codeql_ql/ast/Ast.qll | 11 +++++++++++ ql/ql/src/queries/overlay/InlineOverlayCaller.ql | 5 +++-- .../InlineOverlayCaller/InlineOverlayCaller.expected | 2 +- .../test/queries/overlay/InlineOverlayCaller/Test.qll | 4 ++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/ql/ql/src/codeql_ql/ast/Ast.qll b/ql/ql/src/codeql_ql/ast/Ast.qll index 1e3ac4e8c827..89bdf14d4b2a 100644 --- a/ql/ql/src/codeql_ql/ast/Ast.qll +++ b/ql/ql/src/codeql_ql/ast/Ast.qll @@ -2542,6 +2542,10 @@ private class CallerArg extends AnnotationArg { CallerArg() { this.getValue() = "caller" } } +private class CallerQArg extends AnnotationArg { + CallerQArg() { this.getValue() = "caller?" } +} + private class LocalArg extends AnnotationArg { LocalArg() { this.getValue() = "local" } } @@ -2616,6 +2620,13 @@ class OverlayCaller extends Annotation { override string toString() { result = "overlay[caller]" } } +/** An `overlay[caller?]` annotation. */ +class OverlayCallerQ extends Annotation { + OverlayCallerQ() { this.getName() = "overlay" and this.getArgs(0) instanceof CallerQArg } + + override string toString() { result = "overlay[caller?]" } +} + /** An `overlay[local]` annotation. */ class OverlayLocal extends Annotation { OverlayLocal() { this.getName() = "overlay" and this.getArgs(0) instanceof LocalArg } diff --git a/ql/ql/src/queries/overlay/InlineOverlayCaller.ql b/ql/ql/src/queries/overlay/InlineOverlayCaller.ql index d27a0ade9bbf..0853dfde830e 100644 --- a/ql/ql/src/queries/overlay/InlineOverlayCaller.ql +++ b/ql/ql/src/queries/overlay/InlineOverlayCaller.ql @@ -31,11 +31,12 @@ where mayBeLocal(p) and p.getAnAnnotation() instanceof Inline and not p.getAnAnnotation() instanceof OverlayCaller and + not p.getAnAnnotation() instanceof OverlayCallerQ and not p.isPrivate() select p, "This possibly local non-private inline predicate will not " + "be inlined across the overlay frontier. This may negatively " + "affect evaluation performance. Consider adding an " + - "`overlay[caller]` annotation to allow inlining across the " + - "overlay frontier. Note that adding an `overlay[caller]` " + + "`overlay[caller]` or `overlay[caller?]` annotation to allow inlining across the " + + "overlay frontier. Note that adding an `overlay[caller]` or `overlay[caller?]` " + "annotation affects semantics under overlay evaluation." diff --git a/ql/ql/test/queries/overlay/InlineOverlayCaller/InlineOverlayCaller.expected b/ql/ql/test/queries/overlay/InlineOverlayCaller/InlineOverlayCaller.expected index d89f1dcb8efc..5075797c0dde 100644 --- a/ql/ql/test/queries/overlay/InlineOverlayCaller/InlineOverlayCaller.expected +++ b/ql/ql/test/queries/overlay/InlineOverlayCaller/InlineOverlayCaller.expected @@ -1 +1 @@ -| Test.qll:7:11:7:13 | ClasslessPredicate foo | This possibly local non-private inline predicate will not be inlined across the overlay frontier. This may negatively affect evaluation performance. Consider adding an `overlay[caller]` annotation to allow inlining across the overlay frontier. Note that adding an `overlay[caller]` annotation affects semantics under overlay evaluation. | +| Test.qll:7:11:7:13 | ClasslessPredicate foo | This possibly local non-private inline predicate will not be inlined across the overlay frontier. This may negatively affect evaluation performance. Consider adding an `overlay[caller]` or `overlay[caller?]` annotation to allow inlining across the overlay frontier. Note that adding an `overlay[caller]` or `overlay[caller?]` annotation affects semantics under overlay evaluation. | diff --git a/ql/ql/test/queries/overlay/InlineOverlayCaller/Test.qll b/ql/ql/test/queries/overlay/InlineOverlayCaller/Test.qll index 3e72490ebb01..e25577d91a17 100644 --- a/ql/ql/test/queries/overlay/InlineOverlayCaller/Test.qll +++ b/ql/ql/test/queries/overlay/InlineOverlayCaller/Test.qll @@ -12,3 +12,7 @@ predicate bar(int x) { x = 43 } pragma[inline] private predicate baz(int x) { x = 44 } + +overlay[caller?] +pragma[inline] +predicate baw(int x) { x = 45 }