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

Skip to content

Commit e082451

Browse files
committed
C++ IR: add getDef and deprecated predicates
These are the hand-written changes that complete the automatic changes from the previous commit. - Add deprecated compatibility wrappers for the renamed predicates. - Add a new `Operand.getDef` predicate. - Clarify the QLDoc for all these predicates.
1 parent 206a96d commit e082451

3 files changed

Lines changed: 114 additions & 6 deletions

File tree

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

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Operand extends TOperand {
3232
final IRFunction getEnclosingIRFunction() {
3333
result = getUse().getEnclosingIRFunction()
3434
}
35-
35+
3636
/**
3737
* Gets the `Instruction` that consumes this operand.
3838
*/
@@ -41,12 +41,48 @@ class Operand extends TOperand {
4141
}
4242

4343
/**
44-
* Gets the `Instruction` whose result is the value of the operand.
44+
* Gets the `Instruction` whose result is the value of the operand. Unlike
45+
* `getDef`, this also has a result when `isDefinitionInexact` holds, which
46+
* means that the resulting instruction may only _partially_ or _potentially_
47+
* be the value of this operand.
4548
*/
4649
Instruction getAnyDef() {
4750
none()
4851
}
4952

53+
/**
54+
* Gets the `Instruction` whose result is the value of the operand. Unlike
55+
* `getAnyDef`, this also has no result when `isDefinitionInexact` holds,
56+
* which means that the resulting instruction must always be exactly the be
57+
* the value of this operand.
58+
*/
59+
final Instruction getDef() {
60+
result = this.getAnyDef() and
61+
getDefinitionOverlap() instanceof MustExactlyOverlap
62+
}
63+
64+
/**
65+
* DEPRECATED: renamed to `getUse`.
66+
*
67+
* Gets the `Instruction` that consumes this operand.
68+
*/
69+
deprecated
70+
final Instruction getUseInstruction() {
71+
result = getUse()
72+
}
73+
74+
/**
75+
* DEPRECATED: use `getAnyDef` or `getDef`. The exact replacement for this
76+
* predicate is `getAnyDef`, but most uses of this predicate should probably
77+
* be replaced with `getDef`.
78+
*
79+
* Gets the `Instruction` whose result is the value of the operand.
80+
*/
81+
deprecated
82+
final Instruction getDefinitionInstruction() {
83+
result = getAnyDef()
84+
}
85+
5086
/**
5187
* Gets the overlap relationship between the operand's definition and its use.
5288
*/

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

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Operand extends TOperand {
3232
final IRFunction getEnclosingIRFunction() {
3333
result = getUse().getEnclosingIRFunction()
3434
}
35-
35+
3636
/**
3737
* Gets the `Instruction` that consumes this operand.
3838
*/
@@ -41,12 +41,48 @@ class Operand extends TOperand {
4141
}
4242

4343
/**
44-
* Gets the `Instruction` whose result is the value of the operand.
44+
* Gets the `Instruction` whose result is the value of the operand. Unlike
45+
* `getDef`, this also has a result when `isDefinitionInexact` holds, which
46+
* means that the resulting instruction may only _partially_ or _potentially_
47+
* be the value of this operand.
4548
*/
4649
Instruction getAnyDef() {
4750
none()
4851
}
4952

53+
/**
54+
* Gets the `Instruction` whose result is the value of the operand. Unlike
55+
* `getAnyDef`, this also has no result when `isDefinitionInexact` holds,
56+
* which means that the resulting instruction must always be exactly the be
57+
* the value of this operand.
58+
*/
59+
final Instruction getDef() {
60+
result = this.getAnyDef() and
61+
getDefinitionOverlap() instanceof MustExactlyOverlap
62+
}
63+
64+
/**
65+
* DEPRECATED: renamed to `getUse`.
66+
*
67+
* Gets the `Instruction` that consumes this operand.
68+
*/
69+
deprecated
70+
final Instruction getUseInstruction() {
71+
result = getUse()
72+
}
73+
74+
/**
75+
* DEPRECATED: use `getAnyDef` or `getDef`. The exact replacement for this
76+
* predicate is `getAnyDef`, but most uses of this predicate should probably
77+
* be replaced with `getDef`.
78+
*
79+
* Gets the `Instruction` whose result is the value of the operand.
80+
*/
81+
deprecated
82+
final Instruction getDefinitionInstruction() {
83+
result = getAnyDef()
84+
}
85+
5086
/**
5187
* Gets the overlap relationship between the operand's definition and its use.
5288
*/

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

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Operand extends TOperand {
3232
final IRFunction getEnclosingIRFunction() {
3333
result = getUse().getEnclosingIRFunction()
3434
}
35-
35+
3636
/**
3737
* Gets the `Instruction` that consumes this operand.
3838
*/
@@ -41,12 +41,48 @@ class Operand extends TOperand {
4141
}
4242

4343
/**
44-
* Gets the `Instruction` whose result is the value of the operand.
44+
* Gets the `Instruction` whose result is the value of the operand. Unlike
45+
* `getDef`, this also has a result when `isDefinitionInexact` holds, which
46+
* means that the resulting instruction may only _partially_ or _potentially_
47+
* be the value of this operand.
4548
*/
4649
Instruction getAnyDef() {
4750
none()
4851
}
4952

53+
/**
54+
* Gets the `Instruction` whose result is the value of the operand. Unlike
55+
* `getAnyDef`, this also has no result when `isDefinitionInexact` holds,
56+
* which means that the resulting instruction must always be exactly the be
57+
* the value of this operand.
58+
*/
59+
final Instruction getDef() {
60+
result = this.getAnyDef() and
61+
getDefinitionOverlap() instanceof MustExactlyOverlap
62+
}
63+
64+
/**
65+
* DEPRECATED: renamed to `getUse`.
66+
*
67+
* Gets the `Instruction` that consumes this operand.
68+
*/
69+
deprecated
70+
final Instruction getUseInstruction() {
71+
result = getUse()
72+
}
73+
74+
/**
75+
* DEPRECATED: use `getAnyDef` or `getDef`. The exact replacement for this
76+
* predicate is `getAnyDef`, but most uses of this predicate should probably
77+
* be replaced with `getDef`.
78+
*
79+
* Gets the `Instruction` whose result is the value of the operand.
80+
*/
81+
deprecated
82+
final Instruction getDefinitionInstruction() {
83+
result = getAnyDef()
84+
}
85+
5086
/**
5187
* Gets the overlap relationship between the operand's definition and its use.
5288
*/

0 commit comments

Comments
 (0)