Skip to content

Commit e27aad9

Browse files
authored
Merge pull request github#13987 from aschackmull/java/rangeanalysis-joinorder-fix
Java: Join-order fix in RangeAnalysis.
2 parents af7fe89 + f8a0b6c commit e27aad9

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

java/ql/lib/semmle/code/java/dataflow/RangeAnalysis.qll

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,22 @@ private Guard boundFlowCond(SsaVariable v, Expr e, int delta, boolean upper, boo
257257
or
258258
// guard that tests whether `v2` is bounded by `e + delta + d1 - d2` and
259259
// exists a guard `guardEq` such that `v = v2 - d1 + d2`.
260-
exists(SsaVariable v2, Guard guardEq, boolean eqIsTrue, int d1, int d2 |
261-
guardEq = eqFlowCond(v, ssaRead(v2, d1), d2, true, eqIsTrue) and
262-
result = boundFlowCond(v2, e, delta + d1 - d2, upper, testIsTrue) and
263-
// guardEq needs to control guard
264-
guardEq.directlyControls(result.getBasicBlock(), eqIsTrue)
260+
exists(SsaVariable v2, int d |
261+
// equality needs to control guard
262+
result.getBasicBlock() = eqSsaCondDirectlyControls(v, v2, d) and
263+
result = boundFlowCond(v2, e, delta - d, upper, testIsTrue)
264+
)
265+
}
266+
267+
/**
268+
* Gets a basic block in which `v1` equals `v2 + delta`.
269+
*/
270+
pragma[nomagic]
271+
private BasicBlock eqSsaCondDirectlyControls(SsaVariable v1, SsaVariable v2, int delta) {
272+
exists(Guard guardEq, int d1, int d2, boolean eqIsTrue |
273+
guardEq = eqFlowCond(v1, ssaRead(v2, d1), d2, true, eqIsTrue) and
274+
delta = d2 - d1 and
275+
guardEq.directlyControls(result, eqIsTrue)
265276
)
266277
}
267278

0 commit comments

Comments
 (0)