Skip to content

Commit 092beb8

Browse files
committed
C++: Don't count write operations as uses.
1 parent d34e731 commit 092beb8

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,16 @@ private class ReturnParameterIndirection extends Use, TReturnParamIndirection {
182182
}
183183

184184
private predicate isExplicitUse(Operand op) {
185-
op.getDef() instanceof VariableAddressInstruction and
186-
not exists(LoadInstruction load |
187-
load.getSourceAddressOperand() = op and
188-
load.getAUse().getUse() instanceof InitializeIndirectionInstruction
185+
exists(VariableAddressInstruction vai | vai = op.getDef() |
186+
// Don't include this operand as a use if it only exists to initialize the
187+
// indirection of a parameter.
188+
not exists(LoadInstruction load |
189+
load.getSourceAddressOperand() = op and
190+
load.getAUse().getUse() instanceof InitializeIndirectionInstruction
191+
) and
192+
// Don't include this operand as a use if the only use of the address is for a write
193+
// that definately overrides a variable.
194+
not (explicitWrite(true, _, vai) and exists(unique( | | vai.getAUse())))
189195
)
190196
}
191197

0 commit comments

Comments
 (0)