mirror of
https://github.com/github/codeql.git
synced 2026-05-01 11:45:14 +02:00
C++: Make sign analysis aware of unsigned'ness and accept test changes.
This commit is contained in:
@@ -216,7 +216,9 @@ module SemanticExprConfig {
|
||||
TSsaInstruction(IR::Instruction instr) { instr.hasMemoryResult() } or
|
||||
TSsaOperand(IR::Operand op) { op.isDefinitionInexact() } or
|
||||
TSsaPointerArithmeticGuard(ValueNumber instr) {
|
||||
exists(Guard g, IR::Operand use | use = instr.getAUse() |
|
||||
exists(Guard g, IR::Operand use |
|
||||
use = instr.getAUse() and use.getIRType() instanceof IR::IRAddressType
|
||||
|
|
||||
g.comparesLt(use, _, _, _, _) or
|
||||
g.comparesLt(_, use, _, _, _) or
|
||||
g.comparesEq(use, _, _, _, _) or
|
||||
|
||||
@@ -198,6 +198,16 @@ module SignAnalysis<DeltaSig D, UtilSig<D> Utils> {
|
||||
}
|
||||
}
|
||||
|
||||
/** An expression of an unsigned type. */
|
||||
private class UnsignedExpr extends FlowSignExpr {
|
||||
UnsignedExpr() { Utils::getTrackedType(this) instanceof SemUnsignedIntegerType }
|
||||
|
||||
override Sign getSignRestriction() {
|
||||
result = TPos() or
|
||||
result = TZero()
|
||||
}
|
||||
}
|
||||
|
||||
pragma[nomagic]
|
||||
private predicate binaryExprOperands(SemBinaryExpr binary, SemExpr left, SemExpr right) {
|
||||
binary.getLeftOperand() = left and binary.getRightOperand() = right
|
||||
|
||||
@@ -318,7 +318,7 @@ int test_mult01(int a, int b) {
|
||||
int r = a*b; // -143 .. 253
|
||||
range(r);
|
||||
total += r;
|
||||
range(total); // $ range=">=... * ...+0"
|
||||
range(total); // $ MISSING: range=">=... * ...+0"
|
||||
}
|
||||
if (3 <= a && a <= 11 && -13 <= b && b <= 0) {
|
||||
range(a); // $ range=<=11 range=>=3
|
||||
@@ -366,7 +366,7 @@ int test_mult02(int a, int b) {
|
||||
int r = a*b; // -143 .. 253
|
||||
range(r);
|
||||
total += r;
|
||||
range(total); // $ range=">=... * ...+0"
|
||||
range(total); // $ MISSING: range=">=... * ...+0"
|
||||
}
|
||||
if (0 <= a && a <= 11 && -13 <= b && b <= 0) {
|
||||
range(a); // $ range=<=11 range=>=0
|
||||
@@ -461,7 +461,7 @@ int test_mult04(int a, int b) {
|
||||
int r = a*b; // -391 .. 221
|
||||
range(r);
|
||||
total += r;
|
||||
range(total); // $ range="<=... * ...+0"
|
||||
range(total); // $ MISSING: range="<=... * ...+0"
|
||||
}
|
||||
if (-17 <= a && a <= 0 && -13 <= b && b <= 0) {
|
||||
range(a); // $ range=<=0 range=>=-17
|
||||
@@ -509,7 +509,7 @@ int test_mult05(int a, int b) {
|
||||
int r = a*b; // -391 .. 221
|
||||
range(r);
|
||||
total += r;
|
||||
range(total); // $ range="<=... * ...+0"
|
||||
range(total); // $ MISSING: range="<=... * ...+0"
|
||||
}
|
||||
if (-17 <= a && a <= -2 && -13 <= b && b <= 0) {
|
||||
range(a); // $ range=<=-2 range=>=-17
|
||||
|
||||
Reference in New Issue
Block a user