Merge pull request #21412 from aschackmull/java/binary-assignment

Java: Make Assignment extend BinaryExpr.
This commit is contained in:
Anders Schack-Mulligen
2026-03-05 13:19:45 +01:00
committed by GitHub
28 changed files with 5032 additions and 110 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

@@ -138,13 +138,14 @@ int operatorWS(BinaryExpr expr) {
endOfBinaryLhs(expr, line, lcol) and
startOfBinaryRhs(expr, line, rcol) and
parens = getParensNextToOp(expr) and
result = rcol - lcol + 1 - expr.getOp().length() - parens
result = rcol - lcol - 1 - expr.getOp().length() - parens
)
}
/** 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