-
Notifications
You must be signed in to change notification settings - Fork 2k
Shared/Java: Introduce a shared control flow reachability library and replace the Java Nullness implementation. #20367
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
Merged
Changes from 2 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
db1f399
Java: Preparatory Nullness refactor.
aschackmull 1ebdcdf
Guards: Support integer ranges.
aschackmull 924a8ea
Java: Improve precision of SuccessorType labels in CFG.
aschackmull 452bbf7
Java: Add some more nullness tests.
aschackmull 4a8ffea
Shared: Add control flow reachability lib.
aschackmull 03321ff
Java: Replace nullness implementation.
aschackmull 60d07cf
Java: Clean up IntegerGuards.qll
aschackmull e8f1ec6
Java: Accept guards test results.
aschackmull 2743fc0
Guards: Include ConditionalExpr in exprHasValue.
aschackmull f9ffee0
Java: Minor nullness cleanup.
aschackmull e302616
Java: Accept qltest change.
aschackmull b308c54
Java: Add a change note, and a minor ql comment.
aschackmull be39c4c
Shared: Minor precision improvement.
aschackmull acb4d9f
Shared: Copy some qldoc from Guards.qll
aschackmull 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -208,6 +208,11 @@ module Make< | |
|
|
||
| private newtype TGuardValue = | ||
| TValue(TAbstractSingleValue val, Boolean isVal) or | ||
| TIntRange(int bound, Boolean upper) { | ||
| exists(ConstantExpr c | c.asIntegerValue() + [-1, 0, 1] = bound) and | ||
| bound != 2147483647 and | ||
| bound != -2147483648 | ||
| } or | ||
|
Comment on lines
+211
to
+216
|
||
| TException(Boolean throws) | ||
|
|
||
| private class AbstractSingleValue extends TAbstractSingleValue { | ||
|
|
@@ -238,6 +243,15 @@ module Make< | |
| result = TValue(val, isVal.booleanNot()) | ||
| ) | ||
| or | ||
| exists(int bound, int d, boolean upper | | ||
| upper = true and d = 1 | ||
| or | ||
| upper = false and d = -1 | ||
| | | ||
| this = TIntRange(bound, pragma[only_bind_into](upper)) and | ||
| result = TIntRange(bound + d, pragma[only_bind_into](upper.booleanNot())) | ||
| ) | ||
| or | ||
| exists(boolean throws | | ||
| this = TException(throws) and | ||
| result = TException(throws.booleanNot()) | ||
|
|
@@ -262,6 +276,14 @@ module Make< | |
| /** Gets the constant that this value represents, if any. */ | ||
| ConstantValue asConstantValue() { this = TValue(TValueConstant(result), true) } | ||
|
|
||
| /** | ||
| * Holds if this value represents an integer range. | ||
| * | ||
| * If `upper = true` the range is `(-infinity, bound]`. | ||
| * If `upper = false` the range is `[bound, infinity)`. | ||
| */ | ||
| predicate isIntRange(int bound, boolean upper) { this = TIntRange(bound, upper) } | ||
|
|
||
| /** Holds if this value represents throwing an exception. */ | ||
| predicate isThrowsException() { this = TException(true) } | ||
|
|
||
|
|
@@ -275,6 +297,12 @@ module Make< | |
| this = TValue(val, false) and result = "not " + val.toString() | ||
| ) | ||
| or | ||
| exists(int bound | | ||
| this = TIntRange(bound, true) and result = "Upper bound " + bound.toString() | ||
| or | ||
| this = TIntRange(bound, false) and result = "Lower bound " + bound.toString() | ||
| ) | ||
| or | ||
| exists(boolean throws | this = TException(throws) | | ||
| throws = true and result = "exception" | ||
| or | ||
|
|
@@ -293,6 +321,24 @@ module Make< | |
| b = TValue(b1, true) and | ||
| a1 != b1 | ||
| ) | ||
| or | ||
| exists(int upperbound, int lowerbound | | ||
| a = TIntRange(upperbound, true) and b = TIntRange(lowerbound, false) | ||
| or | ||
| b = TIntRange(upperbound, true) and a = TIntRange(lowerbound, false) | ||
| | | ||
| upperbound < lowerbound | ||
| ) | ||
| or | ||
| exists(int bound, boolean upper, int k | | ||
| a = TIntRange(bound, upper) and b.asIntValue() = k | ||
| or | ||
| b = TIntRange(bound, upper) and a.asIntValue() = k | ||
| | | ||
| upper = true and bound < k | ||
| or | ||
| upper = false and bound > k | ||
| ) | ||
| } | ||
|
|
||
| private predicate constantHasValue(ConstantExpr c, GuardValue v) { | ||
|
|
@@ -681,18 +727,6 @@ module Make< | |
| ) | ||
| } | ||
|
|
||
| /** Holds if `e` may take the value `k` */ | ||
| private predicate relevantInt(Expr e, int k) { | ||
| e.(ConstantExpr).asIntegerValue() = k | ||
| or | ||
| relevantInt(any(Expr e1 | valueStep(e1, e)), k) | ||
| or | ||
| exists(SsaDefinition def | | ||
| guardReadsSsaVar(e, def) and | ||
| relevantInt(getAnUltimateDefinition(def, _).(SsaWriteDefinition).getDefinition(), k) | ||
| ) | ||
| } | ||
|
|
||
| private predicate impliesStep1(Guard g1, GuardValue v1, Guard g2, GuardValue v2) { | ||
| baseImpliesStep(g1, v1, g2, v2) | ||
| or | ||
|
|
@@ -705,14 +739,9 @@ module Make< | |
| not g2.directlyValueControls(g1.getBasicBlock(), v2) | ||
| ) | ||
| or | ||
| exists(int k1, int k2, boolean upper | | ||
| rangeGuard(g1, v1, g2, k1, upper) and | ||
| relevantInt(g2, k2) and | ||
| v2 = TValue(TValueInt(k2), false) | ||
| | | ||
| upper = true and k1 < k2 // g2 <= k1 < k2 ==> g2 != k2 | ||
| or | ||
| upper = false and k1 > k2 // g2 >= k1 > k2 ==> g2 != k2 | ||
| exists(int k, boolean upper | | ||
| rangeGuard(g1, v1, g2, k, upper) and | ||
| v2 = TIntRange(k, upper) | ||
| ) | ||
| or | ||
| exists(boolean isNull | | ||
|
|
||
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.
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.
Total cornercase / nit question: If
cholds the maximum integer value of2147483647shouldn't we then haveTIntRange(2147483646, _)andTIntRange(2147483647, _)(the latter is excluded)?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.
For edge cases like
TIntRange(2147483647, upper)we can easily run into trouble: Ifupper = falsethen this is likely a singleton value set, and quite unlikely as a useful bound. And withupper = true, the bound becomes trivial assuming that it applies to e.g. a Javaint, but worse is that the default computation of its dual lower bound overflows in QL. Simply excluding the edge cases as valid bounds helps avoid that.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.
I'll add a comment in the code.