Rename AnyEqualsExpr and AnyNotEqualsExpr

This commit is contained in:
Tony Torralba
2022-05-05 17:38:02 +02:00
committed by Ian Lynagh
parent 0e3db78eba
commit a5a31db835
7 changed files with 36 additions and 22 deletions

View File

@@ -227,12 +227,12 @@ class CompileTimeConstantExpr extends Expr {
)
or
(
b instanceof AnyEqualsExpr and
b instanceof ValueOrReferenceEqualsExpr and
if left = right then result = true else result = false
)
or
(
b instanceof AnyNotEqualsExpr and
b instanceof ValueOrReferenceNotEqualsExpr and
if left != right then result = true else result = false
)
)
@@ -244,12 +244,12 @@ class CompileTimeConstantExpr extends Expr {
right = b.getRightOperand().(CompileTimeConstantExpr).getBooleanValue()
|
(
b instanceof AnyEqualsExpr and
b instanceof ValueOrReferenceEqualsExpr and
if left = right then result = true else result = false
)
or
(
b instanceof AnyNotEqualsExpr and
b instanceof ValueOrReferenceNotEqualsExpr and
if left != right then result = true else result = false
)
or
@@ -277,12 +277,12 @@ class CompileTimeConstantExpr extends Expr {
*/
(
b instanceof AnyEqualsExpr and
b instanceof ValueOrReferenceEqualsExpr and
if left = right then result = true else result = false
)
or
(
b instanceof AnyNotEqualsExpr and
b instanceof ValueOrReferenceNotEqualsExpr and
if left != right then result = true else result = false
)
)
@@ -366,7 +366,7 @@ class CompileTimeConstantExpr extends Expr {
or
b instanceof XorBitwiseExpr and result = v1.bitXor(v2)
// No `int` value for `AndLogicalExpr` or `OrLogicalExpr`.
// No `int` value for `LTExpr`, `GTExpr`, `LEExpr`, `GEExpr`, `AnyEqualsExpr` or `AnyNotEqualsExpr`.
// No `int` value for `LTExpr`, `GTExpr`, `LEExpr`, `GEExpr`, `ValueOrReferenceEqualsExpr` or `ValueOrReferenceNotEqualsExpr`.
)
or
// Ternary conditional, with compile-time constant condition.
@@ -1006,8 +1006,8 @@ class ValueNEExpr extends BinaryExpr, @valueneexpr {
* This might test for reference equality or might function like `Objects.equals`. If you
* need to distinguish them, use `EQExpr` or `ValueEQExpr` instead.
*/
class AnyEqualsExpr extends BinaryExpr {
AnyEqualsExpr() { this instanceof EQExpr or this instanceof ValueEQExpr }
class ValueOrReferenceEqualsExpr extends BinaryExpr {
ValueOrReferenceEqualsExpr() { this instanceof EQExpr or this instanceof ValueEQExpr }
}
/**
@@ -1016,8 +1016,8 @@ class AnyEqualsExpr extends BinaryExpr {
* This might test for reference equality or might function like `Objects.equals`. If you
* need to distinguish them, use `EQExpr` or `ValueEQExpr` instead.
*/
class AnyNotEqualsExpr extends BinaryExpr {
AnyNotEqualsExpr() { this instanceof NEExpr or this instanceof ValueNEExpr }
class ValueOrReferenceNotEqualsExpr extends BinaryExpr {
ValueOrReferenceNotEqualsExpr() { this instanceof NEExpr or this instanceof ValueNEExpr }
}
/**

View File

@@ -133,12 +133,12 @@ class ConstantExpr extends Expr {
)
or
(
b instanceof AnyEqualsExpr and
b instanceof ValueOrReferenceEqualsExpr and
if left = right then result = true else result = false
)
or
(
b instanceof AnyNotEqualsExpr and
b instanceof ValueOrReferenceNotEqualsExpr and
if left != right then result = true else result = false
)
)

View File

@@ -29,9 +29,9 @@ where
not isDefinitelyPositive(lhs.getLeftOperand()) and
lhs.getRightOperand().(IntegerLiteral).getIntValue() = 2 and
(
t instanceof AnyEqualsExpr and rhs.getIntValue() = 1 and parity = "oddness"
t instanceof ValueOrReferenceEqualsExpr and rhs.getIntValue() = 1 and parity = "oddness"
or
t instanceof AnyNotEqualsExpr and rhs.getIntValue() = 1 and parity = "evenness"
t instanceof ValueOrReferenceNotEqualsExpr and rhs.getIntValue() = 1 and parity = "evenness"
or
t instanceof GTExpr and rhs.getIntValue() = 0 and parity = "oddness"
)

View File

@@ -70,7 +70,7 @@ predicate specialCase(EqualityTest comparison, string msg) {
// Name of boxed type corresponding to `fptp`.
(if fptp.getName().toLowerCase() = "float" then boxedName = "Float" else boxedName = "Double") and
// Equality tests are tests for not-`NaN`, inequality tests for `NaN`.
(if comparison instanceof AnyEqualsExpr then neg = "!" else neg = "") and
(if comparison instanceof ValueOrReferenceEqualsExpr then neg = "!" else neg = "") and
msg = "equivalent to " + neg + boxedName + ".isNaN(" + comparison.getLeftOperand() + ")"
)
}

View File

@@ -16,7 +16,7 @@
import java
/** A comparison (using `==`) with `null`. */
class NullEQExpr extends AnyEqualsExpr {
class NullEQExpr extends ValueOrReferenceEqualsExpr {
NullEQExpr() { exists(NullLiteral l | l.getParent() = this) }
}

View File

@@ -15,13 +15,25 @@ class BoolCompare extends EqualityTest {
predicate simplify(string pattern, string rewrite) {
exists(boolean b | b = this.getAnOperand().(BooleanLiteral).getBooleanValue() |
this instanceof AnyEqualsExpr and b = true and pattern = "A == true" and rewrite = "A"
this instanceof ValueOrReferenceEqualsExpr and
b = true and
pattern = "A == true" and
rewrite = "A"
or
this instanceof AnyNotEqualsExpr and b = false and pattern = "A != false" and rewrite = "A"
this instanceof ValueOrReferenceNotEqualsExpr and
b = false and
pattern = "A != false" and
rewrite = "A"
or
this instanceof AnyEqualsExpr and b = false and pattern = "A == false" and rewrite = "!A"
this instanceof ValueOrReferenceEqualsExpr and
b = false and
pattern = "A == false" and
rewrite = "!A"
or
this instanceof AnyNotEqualsExpr and b = true and pattern = "A != true" and rewrite = "!A"
this instanceof ValueOrReferenceNotEqualsExpr and
b = true and
pattern = "A != true" and
rewrite = "!A"
)
}
}

View File

@@ -42,7 +42,9 @@ class AndroidFileLeakConfig extends TaintTracking::Configuration {
OnActivityForResultMethod oafr, ConditionBlock cb, CompileTimeConstantExpr cc,
VarAccess intentVar
|
cb.getCondition().(AnyEqualsExpr).hasOperands(oafr.getParameter(0).getAnAccess(), cc) and
cb.getCondition()
.(ValueOrReferenceEqualsExpr)
.hasOperands(oafr.getParameter(0).getAnAccess(), cc) and
cc.getIntValue() = any(AndroidFileIntentInput fi).getRequestCode() and
intentVar.getType() instanceof TypeIntent and
cb.controls(intentVar.getBasicBlock(), true) and