Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ed68f91

Browse files
author
Robert Marsh
committed
C++: Initial implementation of new range analysis
1 parent a06a20d commit ed68f91

16 files changed

Lines changed: 2526 additions & 3 deletions

File tree

cpp/ql/src/semmle/code/cpp/controlflow/IRGuards.qll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,17 @@ class IRGuardCondition extends Instruction {
280280
ne.controls(controlled, testIsTrue.booleanNot()))
281281
}
282282

283+
cached predicate controlsEdge(ConditionalBranchInstruction branch, IRBlock succ, boolean testIsTrue) {
284+
branch.getCondition() = this and
285+
(
286+
testIsTrue = true and
287+
succ.getFirstInstruction() = branch.getTrueSuccessor()
288+
or
289+
testIsTrue = false and
290+
succ.getFirstInstruction() = branch.getFalseSuccessor()
291+
)
292+
}
293+
283294
/** Holds if (determined by this guard) `left < right + k` evaluates to `isLessThan` if this expression evaluates to `testIsTrue`. */
284295
cached predicate comparesLt(Operand left, Operand right, int k, boolean isLessThan, boolean testIsTrue) {
285296
compares_lt(this, left, right, k, isLessThan, testIsTrue)

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/Instruction.qll

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ module InstructionSanity {
130130
query predicate instructionWithoutUniqueBlock(Instruction instr, int blockCount) {
131131
blockCount = count(instr.getBlock()) and
132132
blockCount != 1
133-
}
133+
}
134134
}
135135

136136
/**
@@ -750,6 +750,12 @@ class BinaryInstruction extends Instruction {
750750
final Instruction getRightOperand() {
751751
result = getAnOperand().(RightOperand).getDefinitionInstruction()
752752
}
753+
754+
final predicate hasOperands(Operand op1, Operand op2) {
755+
op1 = getAnOperand().(LeftOperand) and op2 = getAnOperand().(RightOperand)
756+
or
757+
op1 = getAnOperand().(RightOperand) and op2 = getAnOperand().(LeftOperand)
758+
}
753759
}
754760

755761
class AddInstruction extends BinaryInstruction {

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/Operand.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ class Operand extends TOperand {
2121
result = "Operand"
2222
}
2323

24+
Location getLocation() {
25+
result = getInstruction().getLocation()
26+
}
27+
2428
/**
2529
* Gets the `Instruction` that consumes this operand.
2630
*/

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/gvn/ValueNumbering.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ private class CongruentCopyInstruction extends CopyInstruction {
107107
def = this.getSourceValue() and
108108
(
109109
def.getResultMemoryAccess() instanceof IndirectMemoryAccess or
110+
def.getResultMemoryAccess() instanceof PhiMemoryAccess or
110111
not def.hasMemoryResult()
111112
)
112113
)

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/Instruction.qll

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ module InstructionSanity {
130130
query predicate instructionWithoutUniqueBlock(Instruction instr, int blockCount) {
131131
blockCount = count(instr.getBlock()) and
132132
blockCount != 1
133-
}
133+
}
134134
}
135135

136136
/**
@@ -750,6 +750,12 @@ class BinaryInstruction extends Instruction {
750750
final Instruction getRightOperand() {
751751
result = getAnOperand().(RightOperand).getDefinitionInstruction()
752752
}
753+
754+
final predicate hasOperands(Operand op1, Operand op2) {
755+
op1 = getAnOperand().(LeftOperand) and op2 = getAnOperand().(RightOperand)
756+
or
757+
op1 = getAnOperand().(RightOperand) and op2 = getAnOperand().(LeftOperand)
758+
}
753759
}
754760

755761
class AddInstruction extends BinaryInstruction {

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/Operand.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ class Operand extends TOperand {
2121
result = "Operand"
2222
}
2323

24+
Location getLocation() {
25+
result = getInstruction().getLocation()
26+
}
27+
2428
/**
2529
* Gets the `Instruction` that consumes this operand.
2630
*/

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/gvn/ValueNumbering.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ private class CongruentCopyInstruction extends CopyInstruction {
107107
def = this.getSourceValue() and
108108
(
109109
def.getResultMemoryAccess() instanceof IndirectMemoryAccess or
110+
def.getResultMemoryAccess() instanceof PhiMemoryAccess or
110111
not def.hasMemoryResult()
111112
)
112113
)

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/Instruction.qll

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ module InstructionSanity {
130130
query predicate instructionWithoutUniqueBlock(Instruction instr, int blockCount) {
131131
blockCount = count(instr.getBlock()) and
132132
blockCount != 1
133-
}
133+
}
134134
}
135135

136136
/**
@@ -750,6 +750,12 @@ class BinaryInstruction extends Instruction {
750750
final Instruction getRightOperand() {
751751
result = getAnOperand().(RightOperand).getDefinitionInstruction()
752752
}
753+
754+
final predicate hasOperands(Operand op1, Operand op2) {
755+
op1 = getAnOperand().(LeftOperand) and op2 = getAnOperand().(RightOperand)
756+
or
757+
op1 = getAnOperand().(RightOperand) and op2 = getAnOperand().(LeftOperand)
758+
}
753759
}
754760

755761
class AddInstruction extends BinaryInstruction {

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/Operand.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ class Operand extends TOperand {
2121
result = "Operand"
2222
}
2323

24+
Location getLocation() {
25+
result = getInstruction().getLocation()
26+
}
27+
2428
/**
2529
* Gets the `Instruction` that consumes this operand.
2630
*/

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/gvn/ValueNumbering.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ private class CongruentCopyInstruction extends CopyInstruction {
107107
def = this.getSourceValue() and
108108
(
109109
def.getResultMemoryAccess() instanceof IndirectMemoryAccess or
110+
def.getResultMemoryAccess() instanceof PhiMemoryAccess or
110111
not def.hasMemoryResult()
111112
)
112113
)

0 commit comments

Comments
 (0)