Skip to content

Commit 25253c7

Browse files
committed
C++: Don't count write operations as uses for IR dataflow. Accept test changes.
1 parent e8afec4 commit 25253c7

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
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
@@ -170,10 +170,16 @@ private class ReturnParameterIndirection extends Use, TReturnParamIndirection {
170170
}
171171

172172
private predicate isExplicitUse(Operand op) {
173-
op.getDef() instanceof VariableAddressInstruction and
174-
not exists(LoadInstruction load |
175-
load.getSourceAddressOperand() = op and
176-
load.getAUse().getUse() instanceof InitializeIndirectionInstruction
173+
exists(VariableAddressInstruction vai | vai = op.getDef() |
174+
// Don't include this operand as a use if it only exists to initialize the
175+
// indirection of a parameter.
176+
not exists(LoadInstruction load |
177+
load.getSourceAddressOperand() = op and
178+
load.getAUse().getUse() instanceof InitializeIndirectionInstruction
179+
) and
180+
// Don't include this operand as a use if the only use of the address is for a write
181+
// that definately overrides a variable.
182+
not (explicitWrite(true, _, vai) and exists(unique( | | vai.getAUse())))
177183
)
178184
}
179185

cpp/ql/test/library-tests/dataflow/dataflow-tests/test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ void regression_with_phi_flow(int clean1) {
490490
while (unknown()) {
491491
x = clean1;
492492
if (unknown()) { }
493-
sink(x); // $ SPURIOUS: ir
493+
sink(x); // clean
494494
x = source();
495495
}
496496
}

0 commit comments

Comments
 (0)