Skip to content

Commit 0e7a082

Browse files
committed
Address review by Anders.
1 parent 5d4b6c3 commit 0e7a082

File tree

2 files changed

+12
-24
lines changed

2 files changed

+12
-24
lines changed

java/ql/src/semmle/code/java/dataflow/NullGuards.qll

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,19 @@ Expr enumConstEquality(Expr e, boolean polarity, EnumConstant c) {
2525
}
2626

2727
/** Gets an instanceof expression of `v` with type `type` */
28-
InstanceOfExpr instanceofExpr(SsaVariable v, Expr type) {
29-
result.getTypeName() = type and
28+
InstanceOfExpr instanceofExpr(SsaVariable v, Type type) {
29+
result.getTypeName().getType() = type and
3030
result.getExpr() = v.getAUse()
3131
}
3232

3333
/**
34-
* Gets an expression of the form `v1` == `v2` or `v1` != `v2`.
34+
* Gets an expression of the form `v1 == v2` or `v1 != v2`.
3535
* The predicate is symmetric in `v1` and `v2`.
3636
*/
37-
BinaryExpr varComparisonExpr(SsaVariable v1, SsaVariable v2, boolean isEqualExpr) {
38-
(
39-
result.getLeftOperand() = v1.getAUse() and
40-
result.getRightOperand() = v2.getAUse()
41-
or
42-
result.getLeftOperand() = v2.getAUse() and
43-
result.getRightOperand() = v1.getAUse()
44-
) and
45-
(
46-
result instanceof EQExpr and
47-
isEqualExpr = true
48-
or
49-
result instanceof NEExpr and
50-
isEqualExpr = false
51-
)
37+
EqualityTest varEqualityTestExpr(SsaVariable v1, SsaVariable v2, boolean isEqualExpr) {
38+
result.hasOperands(v1.getAUse(), v2.getAUse()) and
39+
result instanceof EqualityTest and
40+
isEqualExpr = result.polarity()
5241
}
5342

5443
/** Gets an expression that is provably not `null`. */

java/ql/src/semmle/code/java/dataflow/Nullness.qll

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -516,16 +516,15 @@ private predicate correlatedConditions(
516516
inverted = pol1.booleanXor(pol2)
517517
)
518518
or
519-
exists(SsaVariable v, Expr t1, Expr t2 |
520-
cond1.getCondition() = instanceofExpr(v, t1) and
521-
cond2.getCondition() = instanceofExpr(v, t2) and
522-
t1.getType() = t2.getType() and
519+
exists(SsaVariable v, Type type |
520+
cond1.getCondition() = instanceofExpr(v, type) and
521+
cond2.getCondition() = instanceofExpr(v, type) and
523522
inverted = false
524523
)
525524
or
526525
exists(SsaVariable v1, SsaVariable v2, boolean branch1, boolean branch2 |
527-
cond1.getCondition() = varComparisonExpr(v1, v2, branch1) and
528-
cond2.getCondition() = varComparisonExpr(v1, v2, branch2) and
526+
cond1.getCondition() = varEqualityTestExpr(v1, v2, branch1) and
527+
cond2.getCondition() = varEqualityTestExpr(v1, v2, branch2) and
529528
inverted = branch1.booleanXor(branch2)
530529
)
531530
)

0 commit comments

Comments
 (0)