Skip to content

Commit 66743fb

Browse files
committed
C++: refactor TranslatedReturnStmt
1 parent e0c7849 commit 66743fb

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

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

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,19 @@ abstract class TranslatedReturnStmt extends TranslatedStmt {
404404
final TranslatedFunction getEnclosingFunction() {
405405
result = getTranslatedFunction(stmt.getEnclosingFunction())
406406
}
407+
408+
override Instruction getChildSuccessorInternal(TranslatedElement child, EdgeKind kind) {
409+
exists(int id |
410+
child = this.getChild(id) and
411+
id >= this.getFirstDestructorCallIndex() and
412+
(
413+
result = this.getChild(id + 1).getFirstInstruction(kind)
414+
or
415+
not exists(this.getChild(id + 1)) and
416+
result = this.getEnclosingFunction().getReturnSuccessorInstruction(kind)
417+
)
418+
)
419+
}
407420
}
408421

409422
/**
@@ -421,15 +434,7 @@ class TranslatedReturnValueStmt extends TranslatedReturnStmt, TranslatedVariable
421434
override Instruction getChildSuccessorInternal(TranslatedElement child, EdgeKind kind) {
422435
result = TranslatedVariableInitialization.super.getChildSuccessorInternal(child, kind)
423436
or
424-
exists(int id |
425-
this.getChild(id) = child and
426-
(
427-
result = this.getChild(id + 1).getFirstInstruction(kind)
428-
or
429-
not exists(this.getChild(id + 1)) and
430-
result = this.getEnclosingFunction().getReturnSuccessorInstruction(kind)
431-
)
432-
)
437+
result = TranslatedReturnStmt.super.getChildSuccessorInternal(child, kind)
433438
}
434439

435440
final override TranslatedElement getChildInternal(int id) {
@@ -491,19 +496,7 @@ class TranslatedReturnVoidExpressionStmt extends TranslatedReturnStmt {
491496
result = this.getInstruction(OnlyInstructionTag()) and
492497
kind instanceof GotoEdge
493498
or
494-
exists(int id |
495-
child = this.getChild(id) and
496-
id >= this.getFirstDestructorCallIndex() and
497-
result = this.getChild(id + 1).getFirstInstruction(kind)
498-
)
499-
or
500-
exists(int id |
501-
child = this.getChild(id) and
502-
id >= this.getFirstDestructorCallIndex() and
503-
exists(this.getChild(id)) and
504-
not exists(this.getChild(id + 1)) and
505-
result = this.getEnclosingFunction().getReturnSuccessorInstruction(kind)
506-
)
499+
result = TranslatedReturnStmt.super.getChildSuccessorInternal(child, kind)
507500
}
508501

509502
private TranslatedExpr getExpr() { result = getTranslatedExpr(stmt.getExpr()) }
@@ -580,13 +573,21 @@ class TranslatedNoValueReturnStmt extends TranslatedReturnStmt, TranslatedVariab
580573
result = TranslatedVariableInitialization.super.getChildInternal(id)
581574
}
582575

576+
override Instruction getChildSuccessorInternal(TranslatedElement child, EdgeKind kind) {
577+
result = TranslatedVariableInitialization.super.getChildSuccessorInternal(child, kind)
578+
or
579+
result = TranslatedReturnStmt.super.getChildSuccessorInternal(child, kind)
580+
}
581+
583582
final override Type getTargetType() { result = this.getEnclosingFunction().getReturnType() }
584583

585584
final override TranslatedInitialization getInitialization() { none() }
586585

587586
final override IRVariable getIRVariable() {
588587
result = this.getEnclosingFunction().getReturnVariable()
589588
}
589+
590+
override predicate handlesDestructorsExplicitly() { any() }
590591
}
591592

592593
/**

0 commit comments

Comments
 (0)