mirror of
https://github.com/github/codeql.git
synced 2026-05-04 21:25:44 +02:00
C++: Initial implementation of new range analysis
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -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)
|
||||
}
|
||||
34
cpp/ql/test/library-tests/rangeanalysis/rangeanalysis/test.c
Normal file
34
cpp/ql/test/library-tests/rangeanalysis/rangeanalysis/test.c
Normal 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++;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user