Skip to content

Commit eb94203

Browse files
committed
C++: Add an 'EdgeKind' column to 'getExceptionSuccessorInstruction'.
1 parent 8bb17a7 commit eb94203

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -914,10 +914,10 @@ abstract class TranslatedElement extends TTranslatedElement {
914914
* Gets the instruction to which control should flow if an exception is thrown
915915
* within this element. This will generally return first `catch` block of the
916916
* nearest enclosing `try`, or the `Unwind` instruction for the function if
917-
* there is no enclosing `try`.
917+
* there is no enclosing `try`. The successor edge kind is specified by `kind`.
918918
*/
919-
Instruction getExceptionSuccessorInstruction() {
920-
result = this.getParent().getExceptionSuccessorInstruction()
919+
Instruction getExceptionSuccessorInstruction(EdgeKind kind) {
920+
result = this.getParent().getExceptionSuccessorInstruction(kind)
921921
}
922922

923923
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2566,7 +2566,7 @@ abstract class TranslatedThrowExpr extends TranslatedNonConstantExpr {
25662566
override Instruction getInstructionSuccessor(InstructionTag tag, EdgeKind kind) {
25672567
tag = ThrowTag() and
25682568
kind instanceof ExceptionEdge and
2569-
result = this.getParent().getExceptionSuccessorInstruction()
2569+
result = this.getParent().getExceptionSuccessorInstruction(any(GotoEdge edge))
25702570
}
25712571

25722572
override Instruction getResult() { none() }

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,9 @@ class TranslatedFunction extends TranslatedRootElement, TTranslatedFunction {
222222
)
223223
}
224224

225-
final override Instruction getExceptionSuccessorInstruction() {
226-
result = this.getInstruction(UnwindTag())
225+
final override Instruction getExceptionSuccessorInstruction(EdgeKind kind) {
226+
result = this.getInstruction(UnwindTag()) and
227+
kind instanceof GotoEdge
227228
}
228229

229230
final override Instruction getInstructionRegisterOperand(InstructionTag tag, OperandTag operandTag) {

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -563,13 +563,12 @@ class TranslatedTryStmt extends TranslatedStmt {
563563
// The last catch clause flows to the exception successor of the parent
564564
// of the `try`, because the exception successor of the `try` itself is
565565
// the first catch clause.
566-
kind instanceof GotoEdge and
567566
handler = this.getHandler(stmt.getNumberOfCatchClauses() - 1) and
568-
result = this.getParent().getExceptionSuccessorInstruction()
567+
result = this.getParent().getExceptionSuccessorInstruction(kind)
569568
}
570569

571-
final override Instruction getExceptionSuccessorInstruction() {
572-
result = this.getHandler(0).getFirstInstruction(any(GotoEdge edge))
570+
final override Instruction getExceptionSuccessorInstruction(EdgeKind kind) {
571+
result = this.getHandler(0).getFirstInstruction(kind)
573572
}
574573

575574
private TranslatedElement getHandler(int index) { result = stmt.getTranslatedHandler(index) }
@@ -635,10 +634,10 @@ abstract class TranslatedHandler extends TranslatedStmt {
635634
child = this.getBlock() and result = this.getParent().getChildSuccessor(this, kind)
636635
}
637636

638-
override Instruction getExceptionSuccessorInstruction() {
637+
override Instruction getExceptionSuccessorInstruction(EdgeKind kind) {
639638
// A throw from within a `catch` block flows to the handler for the parent of
640639
// the `try`.
641-
result = this.getParent().getParent().getExceptionSuccessorInstruction()
640+
result = this.getParent().getParent().getExceptionSuccessorInstruction(kind)
642641
}
643642

644643
TranslatedStmt getBlock() { result = getTranslatedStmt(stmt.getBlock()) }

0 commit comments

Comments
 (0)