Skip to content

Commit ba10ea8

Browse files
committed
C++: ReuseExpr IR translation
1 parent f5fed84 commit ba10ea8

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedExpr.qll

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2769,6 +2769,43 @@ class TranslatedTemporaryObjectExpr extends TranslatedNonConstantExpr,
27692769
final override Instruction getResult() { result = this.getTargetAddress() }
27702770
}
27712771

2772+
class TranslatedReuseExpr extends TranslatedNonConstantExpr {
2773+
override ReuseExpr expr;
2774+
2775+
override Instruction getFirstInstruction(EdgeKind kind) {
2776+
result = this.getInstruction(OnlyInstructionTag()) and
2777+
kind instanceof GotoEdge
2778+
}
2779+
2780+
override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
2781+
opcode instanceof Opcode::CopyValue and
2782+
tag instanceof OnlyInstructionTag and
2783+
resultType = this.getResultType()
2784+
}
2785+
2786+
override Instruction getResult() { result = this.getInstruction(OnlyInstructionTag()) }
2787+
2788+
override Instruction getInstructionSuccessorInternal(InstructionTag tag, EdgeKind kind) {
2789+
tag = OnlyInstructionTag() and
2790+
kind instanceof GotoEdge and
2791+
result = this.getParent().getChildSuccessor(this, kind)
2792+
}
2793+
2794+
override TranslatedElement getChildInternal(int id) { none() }
2795+
2796+
override Instruction getALastInstructionInternal() {
2797+
result = this.getInstruction(OnlyInstructionTag())
2798+
}
2799+
2800+
override Instruction getInstructionRegisterOperand(InstructionTag tag, OperandTag operandTag) {
2801+
tag = OnlyInstructionTag() and
2802+
operandTag instanceof UnaryOperandTag and
2803+
if getTranslatedExpr(expr.getReusedExpr()) instanceof TranslatedLoad
2804+
then result = getTranslatedExpr(expr.getReusedExpr()).(TranslatedLoad).getOperand().getResult()
2805+
else result = getTranslatedExpr(expr.getReusedExpr()).getResult()
2806+
}
2807+
}
2808+
27722809
/**
27732810
* IR translation of a `throw` expression.
27742811
*/

0 commit comments

Comments
 (0)