Skip to content

Commit bbee9a8

Browse files
authored
Merge pull request #38 from jbj/ir-Instruction-hasUse
Approved by dave-bartolomeo
2 parents acbe754 + c92111d commit bbee9a8

File tree

8 files changed

+32
-35
lines changed

8 files changed

+32
-35
lines changed

cpp/ql/src/semmle/code/cpp/ir/internal/Instruction.qll

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ module InstructionSanity {
6666
count(instr.getOperand(tag)) > 1 and
6767
not tag instanceof UnmodeledUseOperand
6868
}
69+
70+
query predicate operandAcrossFunctions(
71+
Instruction op, Instruction operand, OperandTag tag
72+
) {
73+
operand = op.getOperand(tag) and
74+
operand.getFunctionIR() != op.getFunctionIR()
75+
}
6976
}
7077

7178
/**
@@ -262,8 +269,8 @@ class Instruction extends Construction::TInstruction {
262269
// Register results are always in SSA form.
263270
not hasMemoryResult() or
264271
// An unmodeled result will have a use on the `UnmodeledUse` instruction.
265-
not exists(UnmodeledUseOperand useTag |
266-
hasUse(_, useTag)
272+
not exists(Instruction useInstr, UnmodeledUseOperand useTag |
273+
this = useInstr.getOperand(useTag)
267274
)
268275
}
269276

@@ -296,15 +303,6 @@ class Instruction extends Construction::TInstruction {
296303
final Instruction getAPredecessor() {
297304
result = getPredecessor(_)
298305
}
299-
300-
/**
301-
* Holds if the result of this instruction is consumed by `useInstruction` as
302-
* an operand with tag `useTag`.
303-
*/
304-
final predicate hasUse(Instruction useInstruction, OperandTag useTag) {
305-
useInstruction.getFunctionIR() = funcIR and
306-
this = useInstruction.getOperand(useTag)
307-
}
308306
}
309307

310308
class VariableInstruction extends Instruction {

cpp/ql/src/semmle/code/cpp/ssa/internal/aliased_ssa/AliasAnalysis.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ predicate operandEscapes(Instruction instr, OperandTag tag) {
160160
predicate resultEscapes(Instruction instr) {
161161
// The result escapes if it has at least one use that escapes.
162162
exists(Instruction useInstr, OperandTag useOperandTag |
163-
instr.hasUse(useInstr, useOperandTag) and
163+
useInstr.getOperand(useOperandTag) = instr and
164164
operandEscapes(useInstr, useOperandTag)
165165
)
166166
}

cpp/ql/src/semmle/code/cpp/ssa/internal/aliased_ssa/Instruction.qll

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ module InstructionSanity {
6666
count(instr.getOperand(tag)) > 1 and
6767
not tag instanceof UnmodeledUseOperand
6868
}
69+
70+
query predicate operandAcrossFunctions(
71+
Instruction op, Instruction operand, OperandTag tag
72+
) {
73+
operand = op.getOperand(tag) and
74+
operand.getFunctionIR() != op.getFunctionIR()
75+
}
6976
}
7077

7178
/**
@@ -262,8 +269,8 @@ class Instruction extends Construction::TInstruction {
262269
// Register results are always in SSA form.
263270
not hasMemoryResult() or
264271
// An unmodeled result will have a use on the `UnmodeledUse` instruction.
265-
not exists(UnmodeledUseOperand useTag |
266-
hasUse(_, useTag)
272+
not exists(Instruction useInstr, UnmodeledUseOperand useTag |
273+
this = useInstr.getOperand(useTag)
267274
)
268275
}
269276

@@ -296,15 +303,6 @@ class Instruction extends Construction::TInstruction {
296303
final Instruction getAPredecessor() {
297304
result = getPredecessor(_)
298305
}
299-
300-
/**
301-
* Holds if the result of this instruction is consumed by `useInstruction` as
302-
* an operand with tag `useTag`.
303-
*/
304-
final predicate hasUse(Instruction useInstruction, OperandTag useTag) {
305-
useInstruction.getFunctionIR() = funcIR and
306-
this = useInstruction.getOperand(useTag)
307-
}
308306
}
309307

310308
class VariableInstruction extends Instruction {

cpp/ql/src/semmle/code/cpp/ssa/internal/ssa/AliasAnalysis.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ predicate operandEscapes(Instruction instr, OperandTag tag) {
160160
predicate resultEscapes(Instruction instr) {
161161
// The result escapes if it has at least one use that escapes.
162162
exists(Instruction useInstr, OperandTag useOperandTag |
163-
instr.hasUse(useInstr, useOperandTag) and
163+
useInstr.getOperand(useOperandTag) = instr and
164164
operandEscapes(useInstr, useOperandTag)
165165
)
166166
}

cpp/ql/src/semmle/code/cpp/ssa/internal/ssa/Instruction.qll

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ module InstructionSanity {
6666
count(instr.getOperand(tag)) > 1 and
6767
not tag instanceof UnmodeledUseOperand
6868
}
69+
70+
query predicate operandAcrossFunctions(
71+
Instruction op, Instruction operand, OperandTag tag
72+
) {
73+
operand = op.getOperand(tag) and
74+
operand.getFunctionIR() != op.getFunctionIR()
75+
}
6976
}
7077

7178
/**
@@ -262,8 +269,8 @@ class Instruction extends Construction::TInstruction {
262269
// Register results are always in SSA form.
263270
not hasMemoryResult() or
264271
// An unmodeled result will have a use on the `UnmodeledUse` instruction.
265-
not exists(UnmodeledUseOperand useTag |
266-
hasUse(_, useTag)
272+
not exists(Instruction useInstr, UnmodeledUseOperand useTag |
273+
this = useInstr.getOperand(useTag)
267274
)
268275
}
269276

@@ -296,15 +303,6 @@ class Instruction extends Construction::TInstruction {
296303
final Instruction getAPredecessor() {
297304
result = getPredecessor(_)
298305
}
299-
300-
/**
301-
* Holds if the result of this instruction is consumed by `useInstruction` as
302-
* an operand with tag `useTag`.
303-
*/
304-
final predicate hasUse(Instruction useInstruction, OperandTag useTag) {
305-
useInstruction.getFunctionIR() = funcIR and
306-
this = useInstruction.getOperand(useTag)
307-
}
308306
}
309307

310308
class VariableInstruction extends Instruction {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
missingOperand
22
unexpectedOperand
33
duplicateOperand
4+
operandAcrossFunctions
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
missingOperand
22
unexpectedOperand
33
duplicateOperand
4+
operandAcrossFunctions
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
missingOperand
22
unexpectedOperand
33
duplicateOperand
4+
operandAcrossFunctions

0 commit comments

Comments
 (0)