Skip to content

Commit dcc4466

Browse files
authored
Merge pull request #2149 from rdmarsh2/rdmarsh/cpp/ir-side-effect-primary
C++: Add getPrimaryInstruction to specific side effects
2 parents 176d767 + 5451c39 commit dcc4466

File tree

16 files changed

+60
-0
lines changed

16 files changed

+60
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,15 @@ module InstructionSanity {
120120
)
121121
}
122122

123+
query predicate sideEffectWithoutPrimary(
124+
SideEffectInstruction instr, string message, IRFunction func, string funcText
125+
) {
126+
not exists(instr.getPrimaryInstruction()) and
127+
message = "Side effect instruction missing primary instruction in function $@" and
128+
func = instr.getEnclosingIRFunction() and
129+
funcText = Language::getIdentityString(func.getFunction())
130+
}
131+
123132
/**
124133
* Holds if an instruction, other than `ExitFunction`, has no successors.
125134
*/

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,15 @@ module InstructionSanity {
120120
)
121121
}
122122

123+
query predicate sideEffectWithoutPrimary(
124+
SideEffectInstruction instr, string message, IRFunction func, string funcText
125+
) {
126+
not exists(instr.getPrimaryInstruction()) and
127+
message = "Side effect instruction missing primary instruction in function $@" and
128+
func = instr.getEnclosingIRFunction() and
129+
funcText = Language::getIdentityString(func.getFunction())
130+
}
131+
123132
/**
124133
* Holds if an instruction, other than `ExitFunction`, has no successors.
125134
*/

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/internal/TranslatedCall.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,11 @@ class TranslatedSideEffect extends TranslatedElement, TTranslatedArgumentSideEff
520520
op instanceof Opcode::IndirectReadSideEffect
521521
}
522522

523+
override Instruction getPrimaryInstructionForSideEffect(InstructionTag tag) {
524+
tag = OnlyInstructionTag() and
525+
result = getTranslatedExpr(call).getInstruction(CallTag())
526+
}
527+
523528
final override int getInstructionIndex(InstructionTag tag) {
524529
tag = OnlyInstructionTag() and
525530
result = index

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,15 @@ module InstructionSanity {
120120
)
121121
}
122122

123+
query predicate sideEffectWithoutPrimary(
124+
SideEffectInstruction instr, string message, IRFunction func, string funcText
125+
) {
126+
not exists(instr.getPrimaryInstruction()) and
127+
message = "Side effect instruction missing primary instruction in function $@" and
128+
func = instr.getEnclosingIRFunction() and
129+
funcText = Language::getIdentityString(func.getFunction())
130+
}
131+
123132
/**
124133
* Holds if an instruction, other than `ExitFunction`, has no successors.
125134
*/

cpp/ql/test/library-tests/ir/ir/aliased_ssa_sanity.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ unexpectedOperand
33
duplicateOperand
44
missingPhiOperand
55
missingOperandType
6+
sideEffectWithoutPrimary
67
instructionWithoutSuccessor
78
ambiguousSuccessors
89
unexplainedLoop

cpp/ql/test/library-tests/ir/ir/raw_sanity.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ unexpectedOperand
33
duplicateOperand
44
missingPhiOperand
55
missingOperandType
6+
sideEffectWithoutPrimary
67
instructionWithoutSuccessor
78
ambiguousSuccessors
89
unexplainedLoop

cpp/ql/test/library-tests/ir/ir/unaliased_ssa_sanity.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ unexpectedOperand
33
duplicateOperand
44
missingPhiOperand
55
missingOperandType
6+
sideEffectWithoutPrimary
67
instructionWithoutSuccessor
78
ambiguousSuccessors
89
unexplainedLoop

cpp/ql/test/library-tests/ir/ssa/aliased_ssa_sanity.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ unexpectedOperand
33
duplicateOperand
44
missingPhiOperand
55
missingOperandType
6+
sideEffectWithoutPrimary
67
instructionWithoutSuccessor
78
ambiguousSuccessors
89
unexplainedLoop

cpp/ql/test/library-tests/ir/ssa/unaliased_ssa_sanity.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ unexpectedOperand
33
duplicateOperand
44
missingPhiOperand
55
missingOperandType
6+
sideEffectWithoutPrimary
67
instructionWithoutSuccessor
78
ambiguousSuccessors
89
unexplainedLoop

cpp/ql/test/library-tests/syntax-zoo/aliased_ssa_sanity.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ duplicateOperand
1010
missingPhiOperand
1111
| cpp11.cpp:141:7:141:7 | Phi: g | cpp11.cpp:161:16:161:16 | NoOp: label ...: |
1212
missingOperandType
13+
sideEffectWithoutPrimary
1314
instructionWithoutSuccessor
1415
| VacuousDestructorCall.cpp:2:29:2:29 | InitializeParameter: y |
1516
| assume0.cpp:7:2:7:2 | Chi: call to f |

0 commit comments

Comments
 (0)