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

@@ -567,7 +567,7 @@ class ThrowStmt extends Stmt, @throwstmt {
or
exists(Stmt mid |
mid = this.findEnclosing() and
not exists(this.catchClauseForThis(mid.(TryStmt))) and
not exists(this.catchClauseForThis(mid)) and
result = mid.getEnclosingStmt()
)
}
@@ -575,7 +575,7 @@ class ThrowStmt extends Stmt, @throwstmt {
private CatchClause catchClauseForThis(TryStmt try) {
result = try.getACatchClause() and
result.getEnclosingCallable() = this.getEnclosingCallable() and
this.getExpr().getType().(RefType).hasSupertype*(result.getVariable().getType().(RefType)) and
this.getExpr().getType().(RefType).hasSupertype*(result.getVariable().getType()) and
not this.getEnclosingStmt+() = result
}

View File

@@ -511,7 +511,7 @@ class RefType extends Type, Annotatable, Modifiable, @reftype {
this.getSourceDeclaration().inherits(f)
)
or
this.hasMethod(m.(Method), _)
this.hasMethod(m, _)
}
/** Holds if this is a top-level type, which is not nested inside any other types. */

View File

@@ -299,7 +299,7 @@ Sign exprSign(Expr e) {
exists(VarAccess access | access = e |
not exists(SsaVariable v | getARead(v) = access) and
(
s = fieldSign(getField(access.(FieldAccess)))
s = fieldSign(getField(access))
or
anySign(s) and not access instanceof FieldAccess
)

View File

@@ -18,12 +18,12 @@ predicate isLive(Callable c) {
* would imply the liveness of `c`.
*/
Callable possibleLivenessCause(Callable c, string reason) {
c.(Method).overridesOrInstantiates(result.(Method)) and
c.(Method).overridesOrInstantiates(result) and
reason = "is overridden or instantiated by"
or
result.calls(c) and reason = "calls"
or
result.callsConstructor(c.(Constructor)) and reason = "calls constructor"
result.callsConstructor(c) and reason = "calls constructor"
or
exists(ClassInstanceExpr e | e.getEnclosingCallable() = result |
e.getConstructor() = c and reason = "constructs"
@@ -243,7 +243,7 @@ class DeadMethod extends Callable {
) and
not (
this.(Method).isAbstract() and
exists(Method m | m.overridesOrInstantiates+(this.(Method)) | isLive(m))
exists(Method m | m.overridesOrInstantiates+(this) | isLive(m))
) and
// A getter or setter associated with a live JPA field.
//

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)
)
}
}