mirror of
https://github.com/github/codeql.git
synced 2026-04-27 01:35:13 +02:00
C++: add getSyntheticDestructor to Expr and Stmt
This commit is contained in:
@@ -58,6 +58,21 @@ class Expr extends StmtParent, @expr {
|
||||
/** Gets the parent of this expression, if any. */
|
||||
Element getParent() { exprparents(underlyingElement(this), _, unresolveElement(result)) }
|
||||
|
||||
/**
|
||||
* Gets the `n`th compiler-generated destructor call that is performed after this expression, in
|
||||
* order of destruction.
|
||||
*/
|
||||
DestructorCall getSyntheticDestructor(int n) {
|
||||
synthetic_destructor_call(this, max(int i | synthetic_destructor_call(this, i, _)) - n, result)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a compiler-generated destructor call that is performed after this expression.
|
||||
*/
|
||||
DestructorCall getASyntheticDestructor() {
|
||||
synthetic_destructor_call(this, _, result)
|
||||
}
|
||||
|
||||
/** Gets the location of this expression. */
|
||||
override Location getLocation() {
|
||||
result = this.getExprLocationOverride()
|
||||
|
||||
@@ -59,6 +59,18 @@ class Stmt extends StmtParent, @stmt {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the `n`th compiler-generated destructor call that is performed after this statement, in
|
||||
* order of destruction.
|
||||
*/
|
||||
DestructorCall getSyntheticDestructor(int n) {
|
||||
synthetic_destructor_call(this, max(int i | synthetic_destructor_call(this, i, _)) - n, result)
|
||||
}
|
||||
|
||||
DestructorCall getASyntheticDestructor() {
|
||||
synthetic_destructor_call(this, _, result)
|
||||
}
|
||||
|
||||
override Location getLocation() { stmts(underlyingElement(this), _, result) }
|
||||
|
||||
override string toString() { none() }
|
||||
|
||||
22
cpp/ql/test/library-tests/destructors/destructors.expected
Normal file
22
cpp/ql/test/library-tests/destructors/destructors.expected
Normal file
@@ -0,0 +1,22 @@
|
||||
exprDestructors
|
||||
stmtDestructors
|
||||
| destructors2.cpp:24:13:24:19 | return ... | 0 | destructors2.cpp:27:5:27:5 | call to ~Class2 | destructors2.cpp:27:5:27:5 | c |
|
||||
| destructors2.cpp:27:5:27:5 | return ... | 0 | destructors2.cpp:27:5:27:5 | call to ~Inner | destructors2.cpp:27:5:27:5 | inner |
|
||||
| destructors2.cpp:27:5:27:5 | return ... | 1 | destructors2.cpp:27:5:27:5 | call to ~Class2 | destructors2.cpp:27:5:27:5 | c |
|
||||
| destructors.cpp:10:5:26:5 | { ... } | 0 | destructors.cpp:26:5:26:5 | call to ~C | destructors.cpp:26:5:26:5 | c21 |
|
||||
| destructors.cpp:10:5:26:5 | { ... } | 1 | destructors.cpp:26:5:26:5 | call to ~C | destructors.cpp:26:5:26:5 | c20 |
|
||||
| destructors.cpp:12:9:14:9 | { ... } | 0 | destructors.cpp:14:9:14:9 | call to ~C | destructors.cpp:14:9:14:9 | c30 |
|
||||
| destructors.cpp:15:9:21:9 | { ... } | 0 | destructors.cpp:21:9:21:9 | call to ~C | destructors.cpp:21:9:21:9 | c33 |
|
||||
| destructors.cpp:15:9:21:9 | { ... } | 1 | destructors.cpp:21:9:21:9 | call to ~C | destructors.cpp:21:9:21:9 | c32 |
|
||||
| destructors.cpp:15:9:21:9 | { ... } | 2 | destructors.cpp:21:9:21:9 | call to ~C | destructors.cpp:21:9:21:9 | c31 |
|
||||
| destructors.cpp:17:21:17:29 | goto ... | 0 | destructors.cpp:21:9:21:9 | call to ~C | destructors.cpp:21:9:21:9 | c31 |
|
||||
| destructors.cpp:17:21:17:29 | goto ... | 1 | destructors.cpp:26:5:26:5 | call to ~C | destructors.cpp:26:5:26:5 | c20 |
|
||||
| destructors.cpp:19:21:19:27 | return ... | 0 | destructors.cpp:21:9:21:9 | call to ~C | destructors.cpp:21:9:21:9 | c32 |
|
||||
| destructors.cpp:19:21:19:27 | return ... | 1 | destructors.cpp:21:9:21:9 | call to ~C | destructors.cpp:21:9:21:9 | c31 |
|
||||
| destructors.cpp:19:21:19:27 | return ... | 2 | destructors.cpp:26:5:26:5 | call to ~C | destructors.cpp:26:5:26:5 | c20 |
|
||||
| destructors.cpp:19:21:19:27 | return ... | 3 | destructors.cpp:35:1:35:1 | call to ~C | destructors.cpp:35:1:35:1 | c10 |
|
||||
| destructors.cpp:22:9:24:9 | { ... } | 0 | destructors.cpp:24:9:24:9 | call to ~C | destructors.cpp:24:9:24:9 | c34 |
|
||||
| destructors.cpp:27:5:29:5 | { ... } | 0 | destructors.cpp:29:5:29:5 | call to ~C | destructors.cpp:29:5:29:5 | c22 |
|
||||
| destructors.cpp:30:5:33:5 | { ... } | 0 | destructors.cpp:33:5:33:5 | call to ~C | destructors.cpp:33:5:33:5 | c23 |
|
||||
| destructors.cpp:35:1:35:1 | return ... | 0 | destructors.cpp:35:1:35:1 | call to ~C | destructors.cpp:35:1:35:1 | c11 |
|
||||
| destructors.cpp:35:1:35:1 | return ... | 1 | destructors.cpp:35:1:35:1 | call to ~C | destructors.cpp:35:1:35:1 | c10 |
|
||||
11
cpp/ql/test/library-tests/destructors/destructors.ql
Normal file
11
cpp/ql/test/library-tests/destructors/destructors.ql
Normal file
@@ -0,0 +1,11 @@
|
||||
import cpp
|
||||
|
||||
query predicate exprDestructors(Expr e, int i, DestructorCall d, Expr destructed) {
|
||||
d = e.getSyntheticDestructor(i) and
|
||||
d.getQualifier() = destructed
|
||||
}
|
||||
|
||||
query predicate stmtDestructors(Stmt s, int i, DestructorCall d, Expr destructed) {
|
||||
d = s.getSyntheticDestructor(i) and
|
||||
d.getQualifier() = destructed
|
||||
}
|
||||
Reference in New Issue
Block a user