Skip to content

Commit b03140d

Browse files
committed
C++: Output destructors of temporary objects
1 parent d892a04 commit b03140d

12 files changed

+2159
-599
lines changed

cpp/ql/lib/semmle/code/cpp/exprs/Expr.qll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,3 +1322,23 @@ class CoYieldExpr extends UnaryOperation, @co_yield {
13221322

13231323
override int getPrecedence() { result = 2 }
13241324
}
1325+
1326+
class ReuseExpr extends Expr, @reuseexpr {
1327+
override string getAPrimaryQlClass() { result = "ReuseExpr" }
1328+
1329+
override string toString() {
1330+
result = "reuse of " + this.getReusedExpr().toString()
1331+
}
1332+
1333+
override Type getType() {
1334+
result = this.getReusedExpr().getType()
1335+
}
1336+
1337+
override string getValueCategoryString() {
1338+
result = this.getReusedExpr().getValueCategoryString()
1339+
}
1340+
1341+
Expr getReusedExpr() {
1342+
expr_reuse(underlyingElement(this), unresolveElement(result))
1343+
}
1344+
}

cpp/ql/lib/semmlecode.cpp.dbscheme

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,6 +1513,11 @@ exprs(
15131513
int location: @location_expr ref
15141514
);
15151515

1516+
expr_reuse(
1517+
int reuse: @expr ref,
1518+
int original: @expr ref
1519+
)
1520+
15161521
/*
15171522
case @value.category of
15181523
1 = prval
@@ -1741,6 +1746,7 @@ case @expr.kind of
17411746
| 360 = @isunsigned
17421747
| 361 = @isvoid
17431748
| 362 = @isvolatile
1749+
| 363 = @reuseexpr
17441750
;
17451751

17461752
@var_args_expr = @vastartexpr

cpp/ql/test/library-tests/ir/ir/PrintAST.expected

Lines changed: 307 additions & 0 deletions
Large diffs are not rendered by default.

cpp/ql/test/library-tests/ir/ir/aliased_ir.expected

Lines changed: 574 additions & 248 deletions
Large diffs are not rendered by default.

cpp/ql/test/library-tests/ir/ir/aliased_ssa_consistency.expected

Lines changed: 60 additions & 0 deletions
Large diffs are not rendered by default.

cpp/ql/test/library-tests/ir/ir/aliased_ssa_consistency_unsound.expected

Lines changed: 60 additions & 0 deletions
Large diffs are not rendered by default.

cpp/ql/test/library-tests/ir/ir/operand_locations.expected

Lines changed: 514 additions & 183 deletions
Large diffs are not rendered by default.

cpp/ql/test/library-tests/ir/ir/raw_consistency.expected

Lines changed: 60 additions & 0 deletions
Large diffs are not rendered by default.

cpp/ql/test/library-tests/ir/ir/raw_ir.expected

Lines changed: 414 additions & 168 deletions
Large diffs are not rendered by default.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class ClassWithDestructor2 {
2+
public:
3+
ClassWithDestructor2();
4+
~ClassWithDestructor2();
5+
6+
char get_x();
7+
};
8+
9+
class ClassWithConstructor {
10+
public:
11+
ClassWithConstructor(char x, char y);
12+
};
13+
14+
char temp_test() {
15+
char x = ClassWithDestructor2().get_x();
16+
ClassWithConstructor y('a', ClassWithDestructor2().get_x());
17+
return ClassWithDestructor2().get_x();
18+
}
19+
20+
21+
char temp_test2() {
22+
new ClassWithDestructor2();
23+
return ClassWithDestructor2().get_x() + ClassWithDestructor2().get_x();
24+
}

0 commit comments

Comments
 (0)