C++: Initial implementation of new range analysis

This commit is contained in:
Robert Marsh
2018-12-06 15:15:40 -08:00
parent a06a20dbab
commit ed68f9150a
16 changed files with 2526 additions and 3 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,12 @@
import semmle.code.cpp.rangeanalysis.RangeAnalysis
import semmle.code.cpp.ir.IR
import semmle.code.cpp.controlflow.IRGuards
import semmle.code.cpp.ir.ValueNumbering
query predicate instructionBounds(Instruction i, Bound b, int delta, boolean upper, Reason reason) {
boundedInstruction(i, b, delta, upper, reason)
}
query predicate operandBounds(Operand op, Bound b, int delta, boolean upper, Reason reason) {
boundedOperand(op, b, delta, upper, reason)
}

View File

@@ -0,0 +1,34 @@
// Guards, inference, critical edges
int test1(int x, int y) {
if (x < y) {
x = y;
}
return x;
}
// Bounds mergers at phi nodes
int test2(int x, int y) {
if (x < y) {
x = y;
} else {
x = x-2;
}
return x;
}
// for loops
int test3(int x, void *p) {
int i;
for (i = 0; i < x; i++) {
p[i];
}
}
// pointer bounds
int test4(int *begin, int *end) {
while (begin < end) {
*begin = (*begin) + 1;
begin++;
}
}