Skip to content

C++: Add getPrimaryInstruction to specific side effects #2149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ module InstructionSanity {
)
}

query predicate sideEffectWithoutPrimary(
SideEffectInstruction instr, string message, IRFunction func, string funcText
) {
not exists(instr.getPrimaryInstruction()) and
message = "Side effect instruction missing primary instruction in function $@" and
func = instr.getEnclosingIRFunction() and
funcText = Language::getIdentityString(func.getFunction())
}

/**
* Holds if an instruction, other than `ExitFunction`, has no successors.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ module InstructionSanity {
)
}

query predicate sideEffectWithoutPrimary(
SideEffectInstruction instr, string message, IRFunction func, string funcText
) {
not exists(instr.getPrimaryInstruction()) and
message = "Side effect instruction missing primary instruction in function $@" and
func = instr.getEnclosingIRFunction() and
funcText = Language::getIdentityString(func.getFunction())
}

/**
* Holds if an instruction, other than `ExitFunction`, has no successors.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,11 @@ class TranslatedSideEffect extends TranslatedElement, TTranslatedArgumentSideEff
op instanceof Opcode::IndirectReadSideEffect
}

override Instruction getPrimaryInstructionForSideEffect(InstructionTag tag) {
tag = OnlyInstructionTag() and
result = getTranslatedExpr(call).getInstruction(CallTag())
}

final override int getInstructionIndex(InstructionTag tag) {
tag = OnlyInstructionTag() and
result = index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ module InstructionSanity {
)
}

query predicate sideEffectWithoutPrimary(
SideEffectInstruction instr, string message, IRFunction func, string funcText
) {
not exists(instr.getPrimaryInstruction()) and
message = "Side effect instruction missing primary instruction in function $@" and
func = instr.getEnclosingIRFunction() and
funcText = Language::getIdentityString(func.getFunction())
}

/**
* Holds if an instruction, other than `ExitFunction`, has no successors.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ unexpectedOperand
duplicateOperand
missingPhiOperand
missingOperandType
sideEffectWithoutPrimary
instructionWithoutSuccessor
ambiguousSuccessors
unexplainedLoop
Expand Down
1 change: 1 addition & 0 deletions cpp/ql/test/library-tests/ir/ir/raw_sanity.expected
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ unexpectedOperand
duplicateOperand
missingPhiOperand
missingOperandType
sideEffectWithoutPrimary
instructionWithoutSuccessor
ambiguousSuccessors
unexplainedLoop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ unexpectedOperand
duplicateOperand
missingPhiOperand
missingOperandType
sideEffectWithoutPrimary
instructionWithoutSuccessor
ambiguousSuccessors
unexplainedLoop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ unexpectedOperand
duplicateOperand
missingPhiOperand
missingOperandType
sideEffectWithoutPrimary
instructionWithoutSuccessor
ambiguousSuccessors
unexplainedLoop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ unexpectedOperand
duplicateOperand
missingPhiOperand
missingOperandType
sideEffectWithoutPrimary
instructionWithoutSuccessor
ambiguousSuccessors
unexplainedLoop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ duplicateOperand
missingPhiOperand
| cpp11.cpp:141:7:141:7 | Phi: g | cpp11.cpp:161:16:161:16 | NoOp: label ...: |
missingOperandType
sideEffectWithoutPrimary
instructionWithoutSuccessor
| VacuousDestructorCall.cpp:2:29:2:29 | InitializeParameter: y |
| assume0.cpp:7:2:7:2 | Chi: call to f |
Expand Down
1 change: 1 addition & 0 deletions cpp/ql/test/library-tests/syntax-zoo/raw_sanity.expected
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ unexpectedOperand
duplicateOperand
missingPhiOperand
missingOperandType
sideEffectWithoutPrimary
instructionWithoutSuccessor
| VacuousDestructorCall.cpp:2:29:2:29 | InitializeParameter: y |
| VacuousDestructorCall.cpp:3:3:3:3 | VariableAddress: x |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ missingPhiOperand
| range_analysis.c:389:3:389:32 | Phi: return ... | range_analysis.c:387:38:387:38 | Constant: 5 |
| range_analysis.c:389:3:389:32 | Phi: return ... | range_analysis.c:387:38:387:38 | Constant: 5 |
missingOperandType
sideEffectWithoutPrimary
instructionWithoutSuccessor
| VacuousDestructorCall.cpp:2:29:2:29 | InitializeParameter: y |
| assume0.cpp:7:2:7:2 | CallSideEffect: call to f |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ module InstructionSanity {
)
}

query predicate sideEffectWithoutPrimary(
SideEffectInstruction instr, string message, IRFunction func, string funcText
) {
not exists(instr.getPrimaryInstruction()) and
message = "Side effect instruction missing primary instruction in function $@" and
func = instr.getEnclosingIRFunction() and
funcText = Language::getIdentityString(func.getFunction())
}

/**
* Holds if an instruction, other than `ExitFunction`, has no successors.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ module InstructionSanity {
)
}

query predicate sideEffectWithoutPrimary(
SideEffectInstruction instr, string message, IRFunction func, string funcText
) {
not exists(instr.getPrimaryInstruction()) and
message = "Side effect instruction missing primary instruction in function $@" and
func = instr.getEnclosingIRFunction() and
funcText = Language::getIdentityString(func.getFunction())
}

/**
* Holds if an instruction, other than `ExitFunction`, has no successors.
*/
Expand Down
1 change: 1 addition & 0 deletions csharp/ql/test/library-tests/ir/ir/raw_ir_sanity.expected
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ unexpectedOperand
duplicateOperand
missingPhiOperand
missingOperandType
sideEffectWithoutPrimary
instructionWithoutSuccessor
ambiguousSuccessors
unexplainedLoop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ unexpectedOperand
duplicateOperand
missingPhiOperand
missingOperandType
sideEffectWithoutPrimary
instructionWithoutSuccessor
ambiguousSuccessors
unexplainedLoop
Expand Down