Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 47720e0

Browse files
author
Robert Marsh
committed
C++: generate instructions for destructor calls in IR
1 parent 643817e commit 47720e0

6 files changed

Lines changed: 123 additions & 64 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ private CallInstruction getTranslatedCallInstruction(Call call) {
2727
* of a higher-level constructor (e.g. the allocator call in a `NewExpr`).
2828
*/
2929
abstract class TranslatedCall extends TranslatedExpr {
30-
final override TranslatedElement getChild(int id) {
30+
final override TranslatedElement getChildInternal(int id) {
3131
// We choose the child's id in the order of evaluation.
3232
// The qualifier is evaluated before the call target, because the value of
3333
// the call target may depend on the value of the qualifier for virtual

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ abstract class TranslatedLocalVariableDeclaration extends TranslatedVariableInit
6060
*/
6161
abstract LocalVariable getVariable();
6262

63+
final override TranslatedElement getChild(int id) {
64+
result = TranslatedVariableInitialization.super.getChildInternal(id)
65+
}
66+
6367
final override Type getTargetType() { result = getVariableType(this.getVariable()) }
6468

6569
final override TranslatedInitialization getInitialization() {

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ private Element getRealParent(Expr expr) {
2424
result = expr.getParentWithConversions()
2525
or
2626
result.(Destructor).getADestruction() = expr
27+
or
28+
result.(Expr).getAnImplicitDestructorCall() = expr
29+
or
30+
result.(Stmt).getAnImplicitDestructorCall() = expr
2731
}
2832

2933
IRUserVariable getIRUserVariable(Declaration decl, Variable var) {
@@ -105,12 +109,6 @@ private predicate ignoreExprOnly(Expr expr) {
105109
newExpr.getAllocatorCall() = expr
106110
)
107111
or
108-
exists(DeleteOrDeleteArrayExpr deleteExpr |
109-
// Ignore the destructor call as we don't model it yet. Don't ignore
110-
// its arguments, though, as they are the arguments to the deallocator.
111-
deleteExpr.getDestructorCall() = expr
112-
)
113-
or
114112
// The extractor deliberately emits an `ErrorExpr` as the first argument to
115113
// the allocator call, if any, of a `NewOrNewArrayExpr`. That `ErrorExpr`
116114
// should not be translated.
@@ -752,7 +750,10 @@ newtype TTranslatedElement =
752750
not ignoreSideEffects(call) and
753751
// Don't bother with destructor calls for now, since we won't see very many of them in the IR
754752
// until we start injecting implicit destructor calls.
755-
call instanceof ConstructorCall and
753+
(
754+
call instanceof ConstructorCall or
755+
call instanceof DestructorCall
756+
) and
756757
opcode = getASideEffectOpcode(call, -1)
757758
} or
758759
// The side effect that initializes newly-allocated memory.

0 commit comments

Comments
 (0)