Skip to content

Commit 0444eb9

Browse files
committed
[TODO]: Only partial solution to range analysis.
1 parent d3c6edb commit 0444eb9

File tree

1 file changed

+20
-1
lines changed
  • csharp/ql/lib/semmle/code/csharp/dataflow/internal/rangeanalysis

1 file changed

+20
-1
lines changed

csharp/ql/lib/semmle/code/csharp/dataflow/internal/rangeanalysis/RangeUtils.qll

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ private module Impl {
3333
/** Holds if SSA definition `def` equals `e + delta`. */
3434
predicate ssaUpdateStep(ExplicitDefinition def, ExprNode e, int delta) {
3535
exists(ControlFlow::Node cfn | cfn = def.getControlFlowNode() |
36-
e = cfn.(ExprNode::Assignment).getRValue() and delta = 0
36+
e = cfn.(ExprNode::Assignment).getRValue() and
37+
delta = 0 and
38+
not cfn instanceof ExprNode::AssignOperation
3739
or
3840
e = cfn.(ExprNode::PostIncrExpr).getOperand() and delta = 1
3941
or
@@ -66,6 +68,12 @@ private module Impl {
6668
x.getIntValue() = delta
6769
)
6870
or
71+
exists(ConstantIntegerExpr x |
72+
e2.(ExprNode::AssignAddExpr).getLeftOperand() = e1 and
73+
e2.(ExprNode::AssignAddExpr).getRightOperand() = x and
74+
x.getIntValue() = delta
75+
)
76+
or
6977
exists(ConstantIntegerExpr x |
7078
e2.(ExprNode::SubExpr).getLeftOperand() = e1 and
7179
e2.(ExprNode::SubExpr).getRightOperand() = x and
@@ -230,6 +238,11 @@ module ExprNode {
230238
override CS::AssignExpr e;
231239
}
232240

241+
/** A compound assignment operation. */
242+
class AssignOperation extends Assignment, BinaryOperation {
243+
override CS::AssignOperation e;
244+
}
245+
233246
/** A unary operation. */
234247
class UnaryOperation extends ExprNode {
235248
override CS::UnaryOperation e;
@@ -327,6 +340,12 @@ module ExprNode {
327340
override TAddOp getOp() { any() }
328341
}
329342

343+
class AssignAddExpr extends AssignOperation {
344+
override CS::AssignAddExpr e;
345+
346+
override TAddOp getOp() { any() }
347+
}
348+
330349
/** A subtraction operation. */
331350
class SubExpr extends BinaryOperation {
332351
override CS::SubExpr e;

0 commit comments

Comments
 (0)