remove redundant inline casts in arguments where the type is inferred by the call target

This commit is contained in:
Erik Krogh Kristensen
2021-10-29 14:37:56 +02:00
parent 15c90adec5
commit d36c66cfca
29 changed files with 51 additions and 60 deletions

View File

@@ -25,7 +25,7 @@ class DangerousAssignOpExpr extends AssignOp {
}
}
predicate problematicCasting(Type t, Expr e) { e.getType().(NumType).widerThan(t.(NumType)) }
predicate problematicCasting(Type t, Expr e) { e.getType().(NumType).widerThan(t) }
from DangerousAssignOpExpr a, Expr e
where

View File

@@ -14,9 +14,7 @@ private import semmle.code.java.controlflow.internal.GuardsLogic
predicate narrowerThanOrEqualTo(ArithExpr exp, NumType numType) {
exp.getType().(NumType).widerThan(numType)
implies
exists(CastExpr cast | cast.getAChildExpr() = exp |
numType.widerThanOrEqualTo(cast.getType().(NumType))
)
exists(CastExpr cast | cast.getAChildExpr() = exp | numType.widerThanOrEqualTo(cast.getType()))
}
private Guard sizeGuard(SsaVariable v, boolean branch, boolean upper) {

View File

@@ -9,7 +9,7 @@ class NumericNarrowingCastExpr extends CastExpr {
exists(NumericType sourceType, NumericType targetType |
sourceType = getExpr().getType() and targetType = getType()
|
not targetType.(NumType).widerThanOrEqualTo(sourceType.(NumType))
not targetType.(NumType).widerThanOrEqualTo(sourceType)
)
}
}