Skip to content
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

java: inline range test #17997

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

yoff
Copy link
Contributor

@yoff yoff commented Nov 15, 2024

This adds inline expectation test for the java range analysis.
Feel free to suggest better tests or better syntax.

Pull Request checklist

All query authors

Internal query authors only

  • Autofixes generated based on these changes are valid, only needed if this PR makes significant changes to .ql, .qll, or .qhelp files. See the documentation (internal access required).
  • Changes are validated at scale (internal access required).
  • Adding a new query? Consider also adding the query to autofix.

@yoff yoff added the no-change-note-required This PR does not need a change note label Nov 15, 2024
@yoff yoff requested a review from a team as a code owner November 15, 2024 11:33
@github-actions github-actions bot added the Java label Nov 15, 2024

public int forloopexitupd() {
int result = 0;
for (; result < 10; result++) { // $ bound="result in [0..9]" bound="result in [0..10]"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I will get that done.


public int emptyforloop() {
int result = 0;
for (int i = 0; i < 0; i++) { // $ bound="i = 0" bound="i in [0..-1]"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@aschackmull
Copy link
Contributor

One of the key features of the range analysis library is the ability to report bounds in terms of SSA variables or interesting expressions such as arr.length. I think it would be nice to add some cases of inline expectations for those bounds as well. Given that they're plentiful, they should only be reported relative to indicated bound expression positions. E.g.

static void bound(int b) { }

static void tst(int[] arr) {
  bound(arr.length);
  for (int i = 0; i < arr.length; i++) {
    arr[i]++; // $ bound="i <= arr.length - 1"
  }
}

But feel free to take or leave this suggestion, depending on how much effort you want to put in, as it's also fine to just merge what's already here in the PR.

Co-authored-by: Anders Schack-Mulligen <aschackmull@users.noreply.github.com>
@yoff
Copy link
Contributor Author

yoff commented Nov 19, 2024

One of the key features of the range analysis library is the ability to report bounds in terms of SSA variables or interesting expressions such as arr.length. I think it would be nice to add some cases of inline expectations for those bounds as well. Given that they're plentiful, they should only be reported relative to indicated bound expression positions. E.g.

I think that is a nice idea. The current set of tests is based on my hunt for opportunities to improve range analysis results by rewriting the CFG. But the current PR should rather just present a useful set of tests for range analysis, so I will give this a go :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Java no-change-note-required This PR does not need a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants