Skip to content

Commit 73e4bfd

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 34c1ec7 commit 73e4bfd

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
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 & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,7 @@ private newtype TIRDataFlowNode =
4242
[getMinIndirectionsForType(var.getUnspecifiedType()) .. SsaImpl::getMaxIndirectionsForType(var.getUnspecifiedType())]
4343
} or
4444
TPostUpdateNodeImpl(Operand operand, int indirectionIndex) {
45-
operand = any(FieldAddress fa).getObjectAddressOperand() and
46-
indirectionIndex =
47-
[0 .. SsaImpl::countIndirectionsForCppType(SsaImpl::getLanguageType(operand))]
48-
or
49-
SsaImpl::isModifiableByCall(operand, indirectionIndex)
45+
isPostUpdateNodeImpl(operand, indirectionIndex)
5046
} or
5147
TSsaSynthNode(SsaImpl::SynthNode n) or
5248
TSsaIteratorNode(IteratorFlow::IteratorFlowNode n) or

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaImpl.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)