Skip to content

Commit 9decb47

Browse files
author
Robert Marsh
authored
Merge pull request #4076 from jbj/SimpleRangeAnalysis-AssignOperation
C++: Fix SimpleRangeAnalysis for AssignOperation
2 parents 4b4b8a9 + f90d779 commit 9decb47

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

cpp/ql/src/semmle/code/cpp/rangeanalysis/SimpleRangeAnalysis.qll

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,17 @@ private predicate assignmentDef(RangeSsaDefinition def, StackVariable v, Expr ex
405405
)
406406
}
407407

408-
/** See comment above sourceDef. */
408+
/** See comment above assignmentDef. */
409409
private predicate analyzableDef(RangeSsaDefinition def, StackVariable v) {
410-
assignmentDef(def, v, _) or defDependsOnDef(def, v, _, _)
410+
assignmentDef(def, v, _)
411+
or
412+
analyzableExpr(def.(AssignOperation)) and
413+
v = def.getAVariable()
414+
or
415+
analyzableExpr(def.(CrementOperation)) and
416+
v = def.getAVariable()
417+
or
418+
phiDependsOnDef(def, v, _, _)
411419
}
412420

413421
/**

cpp/ql/test/library-tests/rangeanalysis/SimpleRangeAnalysis/lowerBound.expected

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,19 +427,19 @@
427427
| test.c:408:7:408:7 | i | 10 |
428428
| test.c:410:3:410:3 | i | -2147483648 |
429429
| test.c:411:3:411:3 | i | 10 |
430-
| test.c:412:7:412:7 | i | -2147483648 |
430+
| test.c:412:7:412:7 | i | 20 |
431431
| test.c:414:3:414:3 | i | -2147483648 |
432432
| test.c:415:3:415:3 | i | 40 |
433-
| test.c:416:7:416:7 | i | -2147483648 |
433+
| test.c:416:7:416:7 | i | 30 |
434434
| test.c:418:3:418:3 | i | -2147483648 |
435435
| test.c:418:7:418:7 | j | -2147483648 |
436436
| test.c:419:7:419:7 | i | 40 |
437437
| test.c:421:3:421:3 | i | -2147483648 |
438438
| test.c:421:8:421:8 | j | 40 |
439439
| test.c:422:7:422:7 | i | 50 |
440440
| test.c:424:3:424:3 | i | -2147483648 |
441-
| test.c:424:13:424:13 | j | -2147483648 |
442-
| test.c:425:7:425:7 | i | -2147483648 |
441+
| test.c:424:13:424:13 | j | 50 |
442+
| test.c:425:7:425:7 | i | 60 |
443443
| test.c:432:12:432:12 | a | 0 |
444444
| test.c:432:17:432:17 | a | 3 |
445445
| test.c:432:33:432:33 | b | 0 |

cpp/ql/test/library-tests/rangeanalysis/SimpleRangeAnalysis/test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ void test17() {
422422
out(i); // 50
423423

424424
i = 20 + (j -= 10);
425-
out(i); // 60 [BUG: the analysis thinks it's 2^-31 .. 2^31-1]
425+
out(i); // 60
426426
}
427427

428428
// Tests for unsigned multiplication.

cpp/ql/test/library-tests/rangeanalysis/SimpleRangeAnalysis/upperBound.expected

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,19 +427,19 @@
427427
| test.c:408:7:408:7 | i | 10 |
428428
| test.c:410:3:410:3 | i | 2147483647 |
429429
| test.c:411:3:411:3 | i | 10 |
430-
| test.c:412:7:412:7 | i | 2147483647 |
430+
| test.c:412:7:412:7 | i | 20 |
431431
| test.c:414:3:414:3 | i | 2147483647 |
432432
| test.c:415:3:415:3 | i | 40 |
433-
| test.c:416:7:416:7 | i | 2147483647 |
433+
| test.c:416:7:416:7 | i | 30 |
434434
| test.c:418:3:418:3 | i | 2147483647 |
435435
| test.c:418:7:418:7 | j | 2147483647 |
436436
| test.c:419:7:419:7 | i | 40 |
437437
| test.c:421:3:421:3 | i | 2147483647 |
438438
| test.c:421:8:421:8 | j | 40 |
439439
| test.c:422:7:422:7 | i | 50 |
440440
| test.c:424:3:424:3 | i | 2147483647 |
441-
| test.c:424:13:424:13 | j | 2147483647 |
442-
| test.c:425:7:425:7 | i | 2147483647 |
441+
| test.c:424:13:424:13 | j | 50 |
442+
| test.c:425:7:425:7 | i | 60 |
443443
| test.c:432:12:432:12 | a | 4294967295 |
444444
| test.c:432:17:432:17 | a | 4294967295 |
445445
| test.c:432:33:432:33 | b | 4294967295 |

0 commit comments

Comments
 (0)