Skip to content

Commit 9de8d5c

Browse files
committed
C++: Reduce the number of uses by excluding conversions.
1 parent 7ecc346 commit 9de8d5c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ private module IteratorIndirections {
208208

209209
override predicate isAdditionalDereference(Instruction deref, Operand address) {
210210
exists(CallInstruction call |
211-
operandForfullyConvertedCall(deref.getAUse(), call) and
211+
operandForfullyConvertedCall(getAUse(deref), call) and
212212
this = call.getStaticCallTarget().getClassAndName("operator*") and
213213
address = call.getThisArgumentOperand()
214214
)
@@ -585,6 +585,15 @@ private module Cached {
585585
)
586586
}
587587

588+
/** Holds if `op` is the only use of its defining instruction, and that op is used in a conversation */
589+
private predicate isConversion(Operand op) {
590+
exists(Instruction def, Operand use |
591+
def = op.getDef() and
592+
use = unique( | | getAUse(def)) and
593+
conversionFlow(use, _, false, false)
594+
)
595+
}
596+
588597
/**
589598
* Holds if `op` is a use of an SSA variable rooted at `base` with `ind` number
590599
* of indirections.
@@ -602,6 +611,9 @@ private module Cached {
602611
type = getLanguageType(op) and
603612
upper = countIndirectionsForCppType(type) and
604613
isUseImpl(op, base, ind0) and
614+
// Don't count every conversion as their own use. Instead, only the first
615+
// use (i.e., before any conversions are applied) will count as a use.
616+
not isConversion(op) and
605617
ind = ind0 + [0 .. upper] and
606618
indirectionIndex = ind - ind0
607619
)

0 commit comments

Comments
 (0)