Skip to content

Commit 93afadf

Browse files
committed
C++: Add and use synthetic_destructor_call table
1 parent 092163a commit 93afadf

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

cpp/ql/src/semmle/code/cpp/controlflow/internal/CFG.qll

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,7 @@ private predicate subEdgeIncludingDestructors(Pos p1, Node n1, Node n2, Pos p2)
984984
// destructors" node. For performance, only do this when the nodes exist.
985985
exists(Pos afterDtors | afterDtors.isAfterDestructors() | subEdge(afterDtors, n1, _, _)) and
986986
not exists(getDestructorCallAfterNode(n1, 0)) and
987+
not synthetic_destructor_call(n1, 0, _) and
987988
p1.nodeBeforeDestructors(n1, n1) and
988989
p2.nodeAfterDestructors(n2, n1)
989990
or
@@ -1011,6 +1012,32 @@ private predicate subEdgeIncludingDestructors(Pos p1, Node n1, Node n2, Pos p2)
10111012
p2.nodeAfterDestructors(n2, n)
10121013
)
10131014
)
1015+
or
1016+
exists(Node n |
1017+
// before destructors -> access(max)
1018+
exists(int maxCallIndex |
1019+
maxCallIndex = max(int i | exists(getSynthesisedDestructorCallAfterNode(n, i))) and
1020+
p1.nodeBeforeDestructors(n1, n) and
1021+
p2.nodeAt(n2, getSynthesisedDestructorCallVariableAccessAfterNode(n, maxCallIndex)))
1022+
or
1023+
// call(i+1) -> access(i)
1024+
exists(int i |
1025+
p1.nodeAt(n1, getSynthesisedDestructorCallAfterNode(n, i + 1)) and
1026+
p2.nodeAt(n2, getSynthesisedDestructorCallVariableAccessAfterNode(n, i))
1027+
)
1028+
or
1029+
// call(0) -> after destructors end
1030+
p1.nodeAt(n1, getSynthesisedDestructorCallAfterNode(n, 0)) and
1031+
p2.nodeAfterDestructors(n2, n)
1032+
)
1033+
}
1034+
1035+
DestructorCall getSynthesisedDestructorCallAfterNode(Node n, int i) {
1036+
synthetic_destructor_call(n, i, result)
1037+
}
1038+
1039+
VariableAccess getSynthesisedDestructorCallVariableAccessAfterNode(Node n, int i) {
1040+
result = getSynthesisedDestructorCallAfterNode(n, i).getChild(-1)
10141041
}
10151042

10161043
/**

cpp/ql/src/semmle/code/cpp/controlflow/internal/SyntheticDestructorCalls.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class SyntheticDestructorCall extends FunctionCall {
3131
not exists(target.getName())
3232
)
3333
) and
34+
not synthetic_destructor_call(_, _, this) and
3435
not exists(this.getParent()) and
3536
not isDeleteDestructorCall(this) and
3637
not this.isUnevaluated() and

cpp/ql/src/semmlecode.cpp.dbscheme

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,11 @@ exprconv(
10411041

10421042
compgenerated(unique int id: @element ref);
10431043

1044+
synthetic_destructor_call(
1045+
int element: @element ref,
1046+
int i: int ref,
1047+
unique int destructor_call: @routineexpr ref
1048+
);
10441049

10451050
namespaces(
10461051
unique int id: @namespace,

0 commit comments

Comments
 (0)