-
Notifications
You must be signed in to change notification settings - Fork 2k
Bound.qll - Replace utility for range analysis duplicate across java and cs with shared file #21900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
BazookaMusic
merged 15 commits into
main
from
bazookamusic/range-analysis-bound-move-to-shared
Jun 4, 2026
+150
−161
Merged
Changes from 7 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6042ade
move identical java and cs bound.qll to shared library
BazookaMusic acb5c0e
missed changes
BazookaMusic cc12740
remove check for files in sync
BazookaMusic 71a3635
formatting
BazookaMusic d1226b7
formatting
BazookaMusic c1c9287
restore file header
BazookaMusic 019a5c0
Merge branch 'main' into bazookamusic/range-analysis-bound-move-to-sh…
BazookaMusic fa63dad
change note
BazookaMusic c610af8
fix comment and add overlay[local?]
BazookaMusic 2a3cff3
more specific comment
BazookaMusic 566a92e
formatting again
BazookaMusic 61a5cec
Merge branch 'main' into bazookamusic/range-analysis-bound-move-to-sh…
BazookaMusic 0a80144
review comments
BazookaMusic f342756
No duplicate Ssa and remove release changenot
BazookaMusic d2972cb
Add back alias for module
BazookaMusic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| /** | ||
| * Provides classes for representing abstract bounds for use in, for example, range analysis. | ||
| */ | ||
| overlay[local?] | ||
| module; | ||
|
|
||
| private import codeql.util.Location | ||
|
|
||
| signature module BoundDefinitions<LocationSig Location> { | ||
| class Type; | ||
|
|
||
| class IntegralType extends Type; | ||
|
|
||
| class ConstantIntegerExpr extends Expr { | ||
| int getIntValue(); | ||
| } | ||
|
|
||
| class SsaSourceVariable { | ||
| Type getType(); | ||
| } | ||
|
|
||
| class SsaVariable { | ||
| SsaSourceVariable getSourceVariable(); | ||
|
|
||
| string toString(); | ||
|
|
||
| Location getLocation(); | ||
|
|
||
| Expr getAUse(); | ||
| } | ||
|
|
||
| class Expr { | ||
| string toString(); | ||
|
|
||
| Location getLocation(); | ||
| } | ||
|
|
||
| predicate interestingExprBound(Expr e); | ||
| } | ||
|
|
||
| /** Provides classes for representing abstract bounds for use in, for example, range analysis. */ | ||
|
BazookaMusic marked this conversation as resolved.
Outdated
|
||
| overlay[local?] | ||
| module Bound<LocationSig Location, BoundDefinitions<Location> Defs> { | ||
| private import Defs | ||
|
|
||
| private newtype TBound = | ||
| TBoundZero() or | ||
| TBoundSsa(SsaVariable v) { v.getSourceVariable().getType() instanceof IntegralType } or | ||
| TBoundExpr(Expr e) { | ||
| interestingExprBound(e) and | ||
| not exists(SsaVariable v | e = v.getAUse()) | ||
| } | ||
|
|
||
| /** | ||
| * A bound that may be inferred for an expression plus/minus an integer delta. | ||
| */ | ||
| abstract class Bound extends TBound { | ||
| /** Gets a textual representation of this bound. */ | ||
| abstract string toString(); | ||
|
|
||
| /** Gets an expression that equals this bound plus `delta`. */ | ||
| abstract Expr getExpr(int delta); | ||
|
|
||
| /** Gets an expression that equals this bound. */ | ||
| Expr getExpr() { result = this.getExpr(0) } | ||
|
|
||
| /** Gets the location of this bound. */ | ||
| abstract Location getLocation(); | ||
| } | ||
|
|
||
| /** | ||
| * The bound that corresponds to the integer 0. This is used to represent all | ||
| * integer bounds as bounds are always accompanied by an added integer delta. | ||
| */ | ||
| class ZeroBound extends Bound, TBoundZero { | ||
| override string toString() { result = "0" } | ||
|
|
||
| override Expr getExpr(int delta) { result.(ConstantIntegerExpr).getIntValue() = delta } | ||
|
|
||
| override Location getLocation() { result.hasLocationInfo("", 0, 0, 0, 0) } | ||
| } | ||
|
|
||
| /** | ||
| * A bound corresponding to the value of an SSA variable. | ||
| */ | ||
| class SsaBound extends Bound, TBoundSsa { | ||
| /** Gets the SSA variable that equals this bound. */ | ||
| SsaVariable getSsa() { this = TBoundSsa(result) } | ||
|
|
||
| override string toString() { result = this.getSsa().toString() } | ||
|
|
||
| override Expr getExpr(int delta) { result = this.getSsa().getAUse() and delta = 0 } | ||
|
|
||
| override Location getLocation() { result = this.getSsa().getLocation() } | ||
| } | ||
|
|
||
| /** | ||
| * A bound that corresponds to the value of a specific expression that might be | ||
| * interesting, but isn't otherwise represented by the value of an SSA variable. | ||
| */ | ||
| class ExprBound extends Bound, TBoundExpr { | ||
| override string toString() { result = this.getExpr().toString() } | ||
|
|
||
| override Expr getExpr(int delta) { this = TBoundExpr(result) and delta = 0 } | ||
|
|
||
| override Location getLocation() { result = this.getExpr().getLocation() } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, there's a reason for naming the resulting module before importing it. It can help provide shorter names in RA/DIL. There's a mechanism in the compiler that makes use of such module aliases to try to shorten names, so we could have
BoundImpl::fooas opposed toSharedBound::Bound<CS::Location, BoundSpecific::BoundDefs>::foo.And it's actually not insignificant - before introducing that mechanism we had a brief period of time where the evaluator log associated with certain runs of the data flow library could yield OOM - simply due to very long names.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting that this mechanism doesn't do something like SharedBound[stable hash of generic arguments appended] so we don't have to name it ourselves. But I will add it back.
I guess we'd need to keep a separate mapping from aliases to modules if we did name generation and there's already one for aliases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh, I didn't know. @aschackmull : Since this is not insignificant, do you know, whether the foundations team will address the issue (either by somehow shortening the names or making it impossible to import without first making an alias)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The OOMs were an extreme case, and that issue was addressed exactly by exploiting aliases defined in QL to shorten names. So mostly this is now just a matter of best practice as it provides slightly easier-to-read logs.