Skip to content

Commit b0ad64c

Browse files
C++: PhiOperand -> PhiInputOperand
Also added `PhiInstruction::getAnInputOperand()`, and renamed `PhiInstruction::getAnOperandDefinitionInstruction()` to `getAnInput()` for consistency with other `Instruction` classes.
1 parent b5a3edf commit b0ad64c

File tree

13 files changed

+68
-47
lines changed

13 files changed

+68
-47
lines changed

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module InstructionSanity {
1515
/**
1616
* Holds if the instruction `instr` should be expected to have an operand
1717
* with operand tag `tag`. Only holds for singleton operand tags. Tags with
18-
* parameters, such as `PhiOperand` and `PositionalArgumentOperand` are handled
18+
* parameters, such as `PhiInputOperand` and `PositionalArgumentOperand` are handled
1919
* separately in `unexpectedOperand`.
2020
*/
2121
private predicate expectsOperand(Instruction instr, OperandTag tag) {
@@ -87,7 +87,7 @@ module InstructionSanity {
8787
*/
8888
query predicate missingPhiOperand(PhiInstruction instr, IRBlock pred) {
8989
pred = instr.getBlock().getAPredecessor() and
90-
not exists(PhiOperand operand |
90+
not exists(PhiInputOperand operand |
9191
operand = instr.getAnOperand() and
9292
operand.getPredecessorBlock() = pred
9393
)
@@ -1622,15 +1622,22 @@ class PhiInstruction extends Instruction {
16221622
result instanceof PhiMemoryAccess
16231623
}
16241624

1625+
/**
1626+
* Gets all of the instruction's `PhiInputOperand`s, representing the values that flow from each predecessor block.
1627+
*/
1628+
final PhiInputOperand getAnInputOperand() {
1629+
result = this.getAnOperand()
1630+
}
1631+
16251632
/**
16261633
* Gets an instruction that defines the input to one of the operands of this
16271634
* instruction. It's possible for more than one operand to have the same
16281635
* defining instruction, so this predicate will have the same number of
1629-
* results as `getAnOperand()` or fewer.
1636+
* results as `getAnInputOperand()` or fewer.
16301637
*/
16311638
pragma[noinline]
1632-
final Instruction getAnOperandDefinitionInstruction() {
1633-
result = this.getAnOperand().(PhiOperand).getDefinitionInstruction()
1639+
final Instruction getAnInput() {
1640+
result = this.getAnInputOperand().getDefinitionInstruction()
16341641
}
16351642
}
16361643

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,12 +379,12 @@ class SideEffectOperand extends TypedOperand {
379379
/**
380380
* An operand of a `PhiInstruction`.
381381
*/
382-
class PhiOperand extends MemoryOperand, TPhiOperand {
382+
class PhiInputOperand extends MemoryOperand, TPhiOperand {
383383
PhiInstruction useInstr;
384384
Instruction defInstr;
385385
IRBlock predecessorBlock;
386386

387-
PhiOperand() {
387+
PhiInputOperand() {
388388
this = TPhiOperand(useInstr, defInstr, predecessorBlock)
389389
}
390390

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/constant/ConstantAnalysis.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ int getConstantValue(Instruction instr) {
1010
result = getConstantValue(instr.(CopyInstruction).getSourceValue()) or
1111
exists(PhiInstruction phi |
1212
phi = instr and
13-
result = max(Instruction def | def = phi.getAnOperandDefinitionInstruction() | getConstantValueToPhi(def)) and
14-
result = min(Instruction def | def = phi.getAnOperandDefinitionInstruction() | getConstantValueToPhi(def))
13+
result = max(Instruction def | def = phi.getAnInput() | getConstantValueToPhi(def)) and
14+
result = min(Instruction def | def = phi.getAnInput() | getConstantValueToPhi(def))
1515
)
1616
}
1717

1818
pragma[noinline]
1919
int getConstantValueToPhi(Instruction def) {
2020
exists(PhiInstruction phi |
2121
result = getConstantValue(def) and
22-
def = phi.getAnOperandDefinitionInstruction()
22+
def = phi.getAnInput()
2323
)
2424
}
2525

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/AliasAnalysis.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private predicate operandEscapesDomain(Operand operand) {
7373
not isArgumentForParameter(_, operand, _) and
7474
not isOnlyEscapesViaReturnArgument(operand) and
7575
not operand.getUseInstruction() instanceof ReturnValueInstruction and
76-
not operand instanceof PhiOperand
76+
not operand instanceof PhiInputOperand
7777
}
7878

7979
/**
@@ -171,7 +171,7 @@ private predicate operandEscapesNonReturn(Operand operand) {
171171
or
172172
isOnlyEscapesViaReturnArgument(operand) and resultEscapesNonReturn(operand.getUseInstruction())
173173
or
174-
operand instanceof PhiOperand and
174+
operand instanceof PhiInputOperand and
175175
resultEscapesNonReturn(operand.getUseInstruction())
176176
or
177177
operandEscapesDomain(operand)
@@ -194,7 +194,7 @@ private predicate operandMayReachReturn(Operand operand) {
194194
or
195195
isOnlyEscapesViaReturnArgument(operand) and resultMayReachReturn(operand.getUseInstruction())
196196
or
197-
operand instanceof PhiOperand and
197+
operand instanceof PhiInputOperand and
198198
resultMayReachReturn(operand.getUseInstruction())
199199
}
200200

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module InstructionSanity {
1515
/**
1616
* Holds if the instruction `instr` should be expected to have an operand
1717
* with operand tag `tag`. Only holds for singleton operand tags. Tags with
18-
* parameters, such as `PhiOperand` and `PositionalArgumentOperand` are handled
18+
* parameters, such as `PhiInputOperand` and `PositionalArgumentOperand` are handled
1919
* separately in `unexpectedOperand`.
2020
*/
2121
private predicate expectsOperand(Instruction instr, OperandTag tag) {
@@ -87,7 +87,7 @@ module InstructionSanity {
8787
*/
8888
query predicate missingPhiOperand(PhiInstruction instr, IRBlock pred) {
8989
pred = instr.getBlock().getAPredecessor() and
90-
not exists(PhiOperand operand |
90+
not exists(PhiInputOperand operand |
9191
operand = instr.getAnOperand() and
9292
operand.getPredecessorBlock() = pred
9393
)
@@ -1622,15 +1622,22 @@ class PhiInstruction extends Instruction {
16221622
result instanceof PhiMemoryAccess
16231623
}
16241624

1625+
/**
1626+
* Gets all of the instruction's `PhiInputOperand`s, representing the values that flow from each predecessor block.
1627+
*/
1628+
final PhiInputOperand getAnInputOperand() {
1629+
result = this.getAnOperand()
1630+
}
1631+
16251632
/**
16261633
* Gets an instruction that defines the input to one of the operands of this
16271634
* instruction. It's possible for more than one operand to have the same
16281635
* defining instruction, so this predicate will have the same number of
1629-
* results as `getAnOperand()` or fewer.
1636+
* results as `getAnInputOperand()` or fewer.
16301637
*/
16311638
pragma[noinline]
1632-
final Instruction getAnOperandDefinitionInstruction() {
1633-
result = this.getAnOperand().(PhiOperand).getDefinitionInstruction()
1639+
final Instruction getAnInput() {
1640+
result = this.getAnInputOperand().getDefinitionInstruction()
16341641
}
16351642
}
16361643

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,12 +379,12 @@ class SideEffectOperand extends TypedOperand {
379379
/**
380380
* An operand of a `PhiInstruction`.
381381
*/
382-
class PhiOperand extends MemoryOperand, TPhiOperand {
382+
class PhiInputOperand extends MemoryOperand, TPhiOperand {
383383
PhiInstruction useInstr;
384384
Instruction defInstr;
385385
IRBlock predecessorBlock;
386386

387-
PhiOperand() {
387+
PhiInputOperand() {
388388
this = TPhiOperand(useInstr, defInstr, predecessorBlock)
389389
}
390390

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/constant/ConstantAnalysis.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ int getConstantValue(Instruction instr) {
1010
result = getConstantValue(instr.(CopyInstruction).getSourceValue()) or
1111
exists(PhiInstruction phi |
1212
phi = instr and
13-
result = max(Instruction def | def = phi.getAnOperandDefinitionInstruction() | getConstantValueToPhi(def)) and
14-
result = min(Instruction def | def = phi.getAnOperandDefinitionInstruction() | getConstantValueToPhi(def))
13+
result = max(Instruction def | def = phi.getAnInput() | getConstantValueToPhi(def)) and
14+
result = min(Instruction def | def = phi.getAnInput() | getConstantValueToPhi(def))
1515
)
1616
}
1717

1818
pragma[noinline]
1919
int getConstantValueToPhi(Instruction def) {
2020
exists(PhiInstruction phi |
2121
result = getConstantValue(def) and
22-
def = phi.getAnOperandDefinitionInstruction()
22+
def = phi.getAnInput()
2323
)
2424
}
2525

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module InstructionSanity {
1515
/**
1616
* Holds if the instruction `instr` should be expected to have an operand
1717
* with operand tag `tag`. Only holds for singleton operand tags. Tags with
18-
* parameters, such as `PhiOperand` and `PositionalArgumentOperand` are handled
18+
* parameters, such as `PhiInputOperand` and `PositionalArgumentOperand` are handled
1919
* separately in `unexpectedOperand`.
2020
*/
2121
private predicate expectsOperand(Instruction instr, OperandTag tag) {
@@ -87,7 +87,7 @@ module InstructionSanity {
8787
*/
8888
query predicate missingPhiOperand(PhiInstruction instr, IRBlock pred) {
8989
pred = instr.getBlock().getAPredecessor() and
90-
not exists(PhiOperand operand |
90+
not exists(PhiInputOperand operand |
9191
operand = instr.getAnOperand() and
9292
operand.getPredecessorBlock() = pred
9393
)
@@ -1622,15 +1622,22 @@ class PhiInstruction extends Instruction {
16221622
result instanceof PhiMemoryAccess
16231623
}
16241624

1625+
/**
1626+
* Gets all of the instruction's `PhiInputOperand`s, representing the values that flow from each predecessor block.
1627+
*/
1628+
final PhiInputOperand getAnInputOperand() {
1629+
result = this.getAnOperand()
1630+
}
1631+
16251632
/**
16261633
* Gets an instruction that defines the input to one of the operands of this
16271634
* instruction. It's possible for more than one operand to have the same
16281635
* defining instruction, so this predicate will have the same number of
1629-
* results as `getAnOperand()` or fewer.
1636+
* results as `getAnInputOperand()` or fewer.
16301637
*/
16311638
pragma[noinline]
1632-
final Instruction getAnOperandDefinitionInstruction() {
1633-
result = this.getAnOperand().(PhiOperand).getDefinitionInstruction()
1639+
final Instruction getAnInput() {
1640+
result = this.getAnInputOperand().getDefinitionInstruction()
16341641
}
16351642
}
16361643

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,12 +379,12 @@ class SideEffectOperand extends TypedOperand {
379379
/**
380380
* An operand of a `PhiInstruction`.
381381
*/
382-
class PhiOperand extends MemoryOperand, TPhiOperand {
382+
class PhiInputOperand extends MemoryOperand, TPhiOperand {
383383
PhiInstruction useInstr;
384384
Instruction defInstr;
385385
IRBlock predecessorBlock;
386386

387-
PhiOperand() {
387+
PhiInputOperand() {
388388
this = TPhiOperand(useInstr, defInstr, predecessorBlock)
389389
}
390390

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/constant/ConstantAnalysis.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ int getConstantValue(Instruction instr) {
1010
result = getConstantValue(instr.(CopyInstruction).getSourceValue()) or
1111
exists(PhiInstruction phi |
1212
phi = instr and
13-
result = max(Instruction def | def = phi.getAnOperandDefinitionInstruction() | getConstantValueToPhi(def)) and
14-
result = min(Instruction def | def = phi.getAnOperandDefinitionInstruction() | getConstantValueToPhi(def))
13+
result = max(Instruction def | def = phi.getAnInput() | getConstantValueToPhi(def)) and
14+
result = min(Instruction def | def = phi.getAnInput() | getConstantValueToPhi(def))
1515
)
1616
}
1717

1818
pragma[noinline]
1919
int getConstantValueToPhi(Instruction def) {
2020
exists(PhiInstruction phi |
2121
result = getConstantValue(def) and
22-
def = phi.getAnOperandDefinitionInstruction()
22+
def = phi.getAnInput()
2323
)
2424
}
2525

0 commit comments

Comments
 (0)