Java: Make Assignment extend BinaryExpr.

This commit is contained in:
Anders Schack-Mulligen
2026-03-04 14:27:53 +01:00
parent 3c129fcd23
commit ec1d034ee0
18 changed files with 32 additions and 83 deletions

View File

@@ -19,6 +19,7 @@ where
lit.getLiteral() = val and
val.regexpMatch("0[0-7][0-7]+") and
lit.getParent() instanceof BinaryExpr and
not lit.getParent() instanceof Assignment and
not lit.getParent() instanceof BitwiseExpr and
not lit.getParent() instanceof ComparisonExpr
select lit, "Integer literal starts with 0."

View File

@@ -145,6 +145,7 @@ int operatorWS(BinaryExpr expr) {
/** Find nested binary expressions where the programmer may have made a precedence mistake. */
predicate interestingNesting(BinaryExpr inner, BinaryExpr outer) {
inner = outer.getAChildExpr() and
not outer instanceof Assignment and
not inner instanceof AssocNestedExpr and
not inner instanceof HarmlessNestedExpr and
not inner.isParenthesized()

View File

@@ -58,6 +58,7 @@ predicate equal(Expr left, Expr right) {
sameVariable(left, right, _)
or
exists(BinaryExpr bLeft, BinaryExpr bRight | bLeft = left and bRight = right |
not bLeft instanceof Assignment and
bLeft.getKind() = bRight.getKind() and
equal(bLeft.getLeftOperand(), bRight.getLeftOperand()) and
equal(bLeft.getRightOperand(), bRight.getRightOperand())

View File

@@ -101,17 +101,10 @@ Expr overFlowCand() {
|
bin instanceof AddExpr or
bin instanceof MulExpr or
bin instanceof LeftShiftExpr
)
or
exists(AssignOp op |
result = op and
positive(op.getDest()) and
positive(op.getRhs())
|
op instanceof AssignAddExpr or
op instanceof AssignMulExpr or
op instanceof AssignLeftShiftExpr
bin instanceof LeftShiftExpr or
bin instanceof AssignAddExpr or
bin instanceof AssignMulExpr or
bin instanceof AssignLeftShiftExpr
)
or
exists(AddExpr add, CompileTimeConstantExpr c |

View File

@@ -36,6 +36,7 @@ Variable flowTarget(Expr arg) {
*/
predicate unboxed(BoxedExpr e) {
exists(BinaryExpr bin | e = bin.getAnOperand() |
not bin instanceof Assignment and
if bin instanceof EqualityTest or bin instanceof ComparisonExpr
then bin.getAnOperand() instanceof PrimitiveExpr
else bin instanceof PrimitiveExpr