|
1 | 1 | import csharp
|
2 | 2 | import Ssa
|
3 |
| -import Bound |
4 |
| -import SignAnalysis |
| 3 | +import semmle.code.csharp.dataflow.internal.rangeanalysis.BoundCommon |
| 4 | +import semmle.code.csharp.dataflow.internal.rangeanalysis.SignAnalysisCommon |
5 | 5 | import semmle.code.csharp.dataflow.internal.rangeanalysis.SsaReadPositionCommon
|
6 | 6 | import semmle.code.csharp.dataflow.internal.rangeanalysis.ConstantUtils
|
7 | 7 | import semmle.code.csharp.dataflow.internal.rangeanalysis.SsaUtils
|
8 |
| -import semmle.code.csharp.dataflow.internal.rangeanalysis.SignAnalysisSpecific::Private as SignPrivate |
| 8 | +import semmle.code.csharp.dataflow.internal.rangeanalysis.RangeUtils |
9 | 9 | import semmle.code.csharp.controlflow.Guards as G
|
10 | 10 | import semmle.code.csharp.commons.ComparisonTest
|
11 | 11 |
|
@@ -61,29 +61,6 @@ private predicate boundCondition(
|
61 | 61 | // todo: other cases: // (v - d) - e < c, ...
|
62 | 62 | }
|
63 | 63 |
|
64 |
| -/** |
65 |
| - * Gets a condition that tests whether `v` equals `e + delta`. |
66 |
| - * |
67 |
| - * If the condition evaluates to `testIsTrue`: |
68 |
| - * - `isEq = true` : `v == e + delta` |
69 |
| - * - `isEq = false` : `v != e + delta` |
70 |
| - */ |
71 |
| -G::Guard eqFlowCond(Definition v, Expr e, int delta, boolean isEq, boolean testIsTrue) { |
72 |
| - exists(boolean eqpolarity | |
73 |
| - result.isEquality(ssaRead(v, delta), e, eqpolarity) and |
74 |
| - (testIsTrue = true or testIsTrue = false) and |
75 |
| - eqpolarity.booleanXor(testIsTrue).booleanNot() = isEq |
76 |
| - ) |
77 |
| - or |
78 |
| - exists( |
79 |
| - boolean testIsTrue0, G::AbstractValues::BooleanValue b0, G::AbstractValues::BooleanValue b1 |
80 |
| - | |
81 |
| - b1.getValue() = testIsTrue and b0.getValue() = testIsTrue0 |
82 |
| - | |
83 |
| - G::Internal::impliesSteps(result, b1, eqFlowCond(v, e, delta, isEq, testIsTrue0), b0) |
84 |
| - ) |
85 |
| -} |
86 |
| - |
87 | 64 | /**
|
88 | 65 | * Gets a condition that tests whether `v` is bounded by `e + delta`.
|
89 | 66 | *
|
@@ -149,27 +126,10 @@ private predicate boundFlowStepSsa(
|
149 | 126 | exists(G::Guard guard, boolean testIsTrue |
|
150 | 127 | pos.hasReadOfVar(v) and
|
151 | 128 | guard = boundFlowCond(v, e, delta, upper, testIsTrue) and
|
152 |
| - SignPrivate::guardControlsSsaRead(guard, pos, testIsTrue) |
| 129 | + guardControlsSsaRead(guard, pos, testIsTrue) |
153 | 130 | )
|
154 | 131 | }
|
155 | 132 |
|
156 |
| -/** |
157 |
| - * Holds if `v` is an `ExplicitDefinition` that equals `e + delta`. |
158 |
| - */ |
159 |
| -predicate ssaUpdateStep(ExplicitDefinition v, Expr e, int delta) { |
160 |
| - v.getADefinition().getExpr().(Assignment).getRValue() = e and delta = 0 |
161 |
| - or |
162 |
| - v.getADefinition().getExpr().(PostIncrExpr).getOperand() = e and delta = 1 |
163 |
| - or |
164 |
| - v.getADefinition().getExpr().(PreIncrExpr).getOperand() = e and delta = 1 |
165 |
| - or |
166 |
| - v.getADefinition().getExpr().(PostDecrExpr).getOperand() = e and delta = -1 |
167 |
| - or |
168 |
| - v.getADefinition().getExpr().(PreDecrExpr).getOperand() = e and delta = -1 |
169 |
| - or |
170 |
| - v.getADefinition().getExpr().(AssignOperation) = e and delta = 0 |
171 |
| -} |
172 |
| - |
173 | 133 | /**
|
174 | 134 | * Holds if `b + delta` is a valid bound for `e`.
|
175 | 135 | * - `upper = true` : `e <= b + delta`
|
@@ -237,59 +197,6 @@ private predicate bounded(
|
237 | 197 | )
|
238 | 198 | }
|
239 | 199 |
|
240 |
| -/** |
241 |
| - * Holds if `e1 + delta` equals `e2`. |
242 |
| - */ |
243 |
| -predicate valueFlowStep(Expr e2, Expr e1, int delta) { |
244 |
| - e2.(AssignExpr).getRValue() = e1 and delta = 0 |
245 |
| - or |
246 |
| - e2.(UnaryPlusExpr).getOperand() = e1 and delta = 0 |
247 |
| - or |
248 |
| - e2.(PostIncrExpr).getOperand() = e1 and delta = 0 |
249 |
| - or |
250 |
| - e2.(PostDecrExpr).getOperand() = e1 and delta = 0 |
251 |
| - or |
252 |
| - e2.(PreIncrExpr).getOperand() = e1 and delta = 1 |
253 |
| - or |
254 |
| - e2.(PreDecrExpr).getOperand() = e1 and delta = -1 |
255 |
| - or |
256 |
| - // exists(ArrayCreationExpr a | |
257 |
| - // arrayLengthDef(e2, a) and |
258 |
| - // a.getDimension(0) = e1 and |
259 |
| - // delta = 0 |
260 |
| - // ) |
261 |
| - // or |
262 |
| - exists(Expr x | |
263 |
| - e2.(AddExpr).getAnOperand() = e1 and |
264 |
| - e2.(AddExpr).getAnOperand() = x and |
265 |
| - not e1 = x |
266 |
| - or |
267 |
| - exists(AssignAddExpr add | add = e2 | |
268 |
| - add.getLValue() = e1 and add.getRValue() = x |
269 |
| - or |
270 |
| - add.getLValue() = x and add.getRValue() = e1 |
271 |
| - ) |
272 |
| - | |
273 |
| - x.(ConstantIntegerExpr).getIntValue() = delta |
274 |
| - ) |
275 |
| - or |
276 |
| - exists(Expr x | |
277 |
| - exists(SubExpr sub | |
278 |
| - e2 = sub and |
279 |
| - sub.getLeftOperand() = e1 and |
280 |
| - sub.getRightOperand() = x |
281 |
| - ) |
282 |
| - or |
283 |
| - exists(AssignSubExpr sub | |
284 |
| - e2 = sub and |
285 |
| - sub.getLValue() = e1 and |
286 |
| - sub.getRValue() = x |
287 |
| - ) |
288 |
| - | |
289 |
| - x.(ConstantIntegerExpr).getIntValue() = -delta |
290 |
| - ) |
291 |
| -} |
292 |
| - |
293 | 200 | /**
|
294 | 201 | * Holds if `e1 + delta` is a valid bound for `e2`.
|
295 | 202 | * - `upper = true` : `e2 <= e1 + delta`
|
@@ -465,7 +372,7 @@ private predicate unequalFlowStepIntegralSsa(Definition v, SsaReadPosition pos,
|
465 | 372 | exists(G::Guard guard, boolean testIsTrue |
|
466 | 373 | pos.hasReadOfVar(v) and
|
467 | 374 | guard = eqFlowCond(v, e, delta, false, testIsTrue) and
|
468 |
| - SignPrivate::guardControlsSsaRead(guard, pos, testIsTrue) |
| 375 | + guardControlsSsaRead(guard, pos, testIsTrue) |
469 | 376 | )
|
470 | 377 | }
|
471 | 378 |
|
|
0 commit comments