Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions java/ql/src/semmle/code/java/dataflow/RangeAnalysis.qll
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,11 @@ private predicate boundFlowStepSsa(
)
}

/** Holds if `v != e + delta` at `pos`. */
private predicate unequalFlowStepSsa(
/** Holds if `v != e + delta` at `pos` and `v` is of integral type. */
private predicate unequalFlowStepIntegralSsa(
SsaVariable v, SsaReadPosition pos, Expr e, int delta, Reason reason
) {
v.getSourceVariable().getType() instanceof IntegralType and
exists(Guard guard, boolean testIsTrue |
pos.hasReadOfVar(v) and
guard = eqFlowCond(v, e, delta, false, testIsTrue) and
Expand Down Expand Up @@ -555,7 +556,7 @@ private predicate boundedSsa(
boundedSsa(v, pos, b, d, upper, fromBackEdge, origdelta, r2) or
boundedPhi(v, b, d, upper, fromBackEdge, origdelta, r2)
|
unequalSsa(v, pos, b, d, r1) and
unequalIntegralSsa(v, pos, b, d, r1) and
(
upper = true and delta = d - 1
or
Expand All @@ -570,11 +571,13 @@ private predicate boundedSsa(
}

/**
* Holds if `v != b + delta` at `pos`.
* Holds if `v != b + delta` at `pos` and `v` is of integral type.
*/
private predicate unequalSsa(SsaVariable v, SsaReadPosition pos, Bound b, int delta, Reason reason) {
private predicate unequalIntegralSsa(
SsaVariable v, SsaReadPosition pos, Bound b, int delta, Reason reason
) {
exists(Expr e, int d1, int d2 |
unequalFlowStepSsa(v, pos, e, d1, reason) and
unequalFlowStepIntegralSsa(v, pos, e, d1, reason) and
bounded(e, b, d2, true, _, _, _) and
bounded(e, b, d2, false, _, _, _) and
delta = d2 + d1
Expand Down
6 changes: 6 additions & 0 deletions java/ql/test/query-tests/UselessComparisonTest/C.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class C {
double m1(double x) {
return (x < 0 || x > 1 || Double.isNaN(x)) ? Double.NaN :
x == 0 ? 0 : x == 1 ? 1 : 0.5;
}
}