Skip to content

Commit d7ae9f0

Browse files
committed
C++: Fix missing flow by also generating final global uses for functions that have a post-update node for the global variable.
1 parent d5d1498 commit d7ae9f0

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,13 @@ private module IndirectInstructions {
332332

333333
import IndirectInstructions
334334

335+
predicate isPostUpdateNodeImpl(Operand operand, int indirectionIndex) {
336+
operand = any(FieldAddress fa).getObjectAddressOperand() and
337+
indirectionIndex = [0 .. Ssa::countIndirectionsForCppType(Ssa::getLanguageType(operand))]
338+
or
339+
Ssa::isModifiableByCall(operand, indirectionIndex)
340+
}
341+
335342
/** Gets the callable in which this node occurs. */
336343
DataFlowCallable nodeGetEnclosingCallable(Node n) { result = n.getEnclosingCallable() }
337344

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ private newtype TIRDataFlowNode =
4242
[getMinIndirectionsForType(var.getUnspecifiedType()) .. Ssa::getMaxIndirectionsForType(var.getUnspecifiedType())]
4343
} or
4444
TPostUpdateNodeImpl(Operand operand, int indirectionIndex) {
45-
operand = any(FieldAddress fa).getObjectAddressOperand() and
46-
indirectionIndex = [0 .. Ssa::countIndirectionsForCppType(Ssa::getLanguageType(operand))]
47-
or
48-
Ssa::isModifiableByCall(operand, indirectionIndex)
45+
isPostUpdateNodeImpl(operand, indirectionIndex)
4946
} or
5047
TSsaSynthNode(Ssa::SynthNode n) or
5148
TSsaIteratorNode(IteratorFlow::IteratorFlowNode n) or

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaInternals.qll

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,14 @@ private predicate isGlobalUse(
143143
min(int cand, VariableAddressInstruction vai |
144144
vai.getEnclosingIRFunction() = f and
145145
vai.getAstVariable() = v and
146-
isDef(_, _, _, vai, cand, indirectionIndex)
146+
(
147+
isDef(_, _, _, vai, cand, indirectionIndex)
148+
or
149+
exists(Operand operand |
150+
isUse(_, operand, vai, cand, indirectionIndex) and
151+
isPostUpdateNodeImpl(operand, indirectionIndex)
152+
)
153+
)
147154
|
148155
cand
149156
)

0 commit comments

Comments
 (0)