Skip to content

Commit 1be2380

Browse files
committed
C++: Rephrase ThisFlow to get space for ctor inits
1 parent f3f89ff commit 1be2380

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowUtil.qll

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -313,17 +313,18 @@ DefinitionByReferenceNode definitionByReferenceNodeFromArgument(Expr argument) {
313313
UninitializedNode uninitializedNode(LocalVariable v) { result.getLocalVariable() = v }
314314

315315
private module ThisFlow {
316-
private Node thisAccessNode(ControlFlowNode cfn) {
317-
result.(ImplicitParameterNode).getFunction().getBlock() = cfn or
318-
result.asExpr().(ThisExpr) = cfn
319-
}
320-
321316
private int basicBlockThisIndex(BasicBlock b, Node thisNode) {
322-
thisNode = thisAccessNode(b.getNode(result))
317+
// The implicit `this` parameter node is given a very negative offset to
318+
// make space for any `ConstructorFieldInit`s there may be between it and
319+
// the block contents.
320+
thisNode.(ImplicitParameterNode).getFunction().getBlock() = b and
321+
result = -1000
322+
or
323+
b.getNode(result) = thisNode.asExpr().(ThisExpr)
323324
}
324325

325326
private int thisRank(BasicBlock b, Node thisNode) {
326-
thisNode = rank[result](thisAccessNode(_) as node order by basicBlockThisIndex(b, node))
327+
thisNode = rank[result](Node n, int i | i = basicBlockThisIndex(b, n) | n order by i)
327328
}
328329

329330
private int lastThisRank(BasicBlock b) { result = max(thisRank(b, _)) }

0 commit comments

Comments
 (0)