Skip to content

Commit 3fc02ce

Browse files
author
Dave Bartolomeo
committed
C++: Fix join order in virtual dispatch with unique
The optimizer picked a terrible join order in `VirtualDispatch::DataSensitiveCall::flowsFrom()`. Telling it that `getAnOutNode()` has a unique result convinces it to join first on the `Callable`, rather than on the `ReturnKind`.
1 parent c511cc3 commit 3fc02ce

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,13 @@ private class SideEffectOutNode extends OutNode {
123123
* `kind`.
124124
*/
125125
OutNode getAnOutNode(DataFlowCall call, ReturnKind kind) {
126-
result.getCall() = call and
127-
result.getReturnKind() = kind
126+
// There should be only one `OutNode` for a given `(call, kind)` pair. Showing the optimizer that
127+
// this is true helps it make better decisions downstream, especially in virtual dispatch.
128+
result =
129+
unique(OutNode outNode |
130+
outNode.getCall() = call and
131+
outNode.getReturnKind() = kind
132+
)
128133
}
129134

130135
/**

0 commit comments

Comments
 (0)