Skip to content

Commit 7ecc346

Browse files
committed
C++: Add another column to 'conversionFlow'.
1 parent 9573395 commit 7ecc346

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ class ReturnIndirectionNode extends IndirectReturnNode, ReturnNode {
370370
private Operand fullyConvertedCallStep(Operand op) {
371371
not exists(getANonConversionUse(op)) and
372372
exists(Instruction instr |
373-
conversionFlow(op, instr, _) and
373+
conversionFlow(op, instr, _, _) and
374374
result = getAUse(instr)
375375
)
376376
}
@@ -397,7 +397,7 @@ Operand getAUse(Instruction instr) {
397397
*/
398398
private Instruction getANonConversionUse(Operand operand) {
399399
result = getUse(operand) and
400-
not conversionFlow(_, result, _)
400+
not conversionFlow(_, result, _, _)
401401
}
402402

403403
/**
@@ -555,7 +555,7 @@ private predicate numberOfLoadsFromOperandRec(Operand operandFrom, Operand opera
555555
or
556556
exists(Operand op, Instruction instr |
557557
instr = op.getDef() and
558-
conversionFlow(operandFrom, instr, _) and
558+
conversionFlow(operandFrom, instr, _, _) and
559559
numberOfLoadsFromOperand(op, operandTo, ind)
560560
)
561561
}
@@ -568,7 +568,7 @@ private predicate numberOfLoadsFromOperand(Operand operandFrom, Operand operandT
568568
numberOfLoadsFromOperandRec(operandFrom, operandTo, n)
569569
or
570570
not Ssa::isDereference(_, operandFrom) and
571-
not conversionFlow(operandFrom, _, _) and
571+
not conversionFlow(operandFrom, _, _, _) and
572572
operandFrom = operandTo and
573573
n = 0
574574
}

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

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,22 +77,32 @@ class FieldAddress extends Operand {
7777
*
7878
* `isPointerArith` is `true` if `instrTo` is a `PointerArithmeticInstruction` and `opFrom`
7979
* is the left operand.
80+
*
81+
* `additional` is `true` if the conversion is supplied by an implementation of the
82+
* `Indirection` class. It is sometimes useful to exclude such conversions.
8083
*/
81-
predicate conversionFlow(Operand opFrom, Instruction instrTo, boolean isPointerArith) {
84+
predicate conversionFlow(
85+
Operand opFrom, Instruction instrTo, boolean isPointerArith, boolean additional
86+
) {
8287
isPointerArith = false and
8388
(
84-
instrTo.(CopyValueInstruction).getSourceValueOperand() = opFrom
85-
or
86-
instrTo.(ConvertInstruction).getUnaryOperand() = opFrom
87-
or
88-
instrTo.(CheckedConvertOrNullInstruction).getUnaryOperand() = opFrom
89-
or
90-
instrTo.(InheritanceConversionInstruction).getUnaryOperand() = opFrom
89+
additional = false and
90+
(
91+
instrTo.(CopyValueInstruction).getSourceValueOperand() = opFrom
92+
or
93+
instrTo.(ConvertInstruction).getUnaryOperand() = opFrom
94+
or
95+
instrTo.(CheckedConvertOrNullInstruction).getUnaryOperand() = opFrom
96+
or
97+
instrTo.(InheritanceConversionInstruction).getUnaryOperand() = opFrom
98+
)
9199
or
100+
additional = true and
92101
Ssa::isAdditionalConversionFlow(opFrom, instrTo)
93102
)
94103
or
95104
isPointerArith = true and
105+
additional = false and
96106
instrTo.(PointerArithmeticInstruction).getLeftOperand() = opFrom
97107
}
98108

@@ -1365,7 +1375,7 @@ private module Cached {
13651375

13661376
private predicate simpleInstructionLocalFlowStep(Operand opFrom, Instruction iTo) {
13671377
// Treat all conversions as flow, even conversions between different numeric types.
1368-
conversionFlow(opFrom, iTo, false)
1378+
conversionFlow(opFrom, iTo, false, _)
13691379
or
13701380
iTo.(CopyInstruction).getSourceValueOperand() = opFrom
13711381
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ private predicate indirectConversionFlowStep(Node nFrom, Node nTo) {
469469
hasOperandAndIndex(nFrom, op1, pragma[only_bind_into](indirectionIndex)) and
470470
hasOperandAndIndex(nTo, op2, pragma[only_bind_into](indirectionIndex)) and
471471
instr = op2.getDef() and
472-
conversionFlow(op1, instr, _)
472+
conversionFlow(op1, instr, _, _)
473473
)
474474
}
475475

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ private module Cached {
652652
exists(Operand mid, Instruction instr |
653653
isUseImpl(mid, base, ind) and
654654
instr = operand.getDef() and
655-
conversionFlow(mid, instr, false)
655+
conversionFlow(mid, instr, false, _)
656656
)
657657
or
658658
exists(int ind0 |
@@ -722,7 +722,7 @@ private module Cached {
722722
exists(Operand mid, Instruction instr, boolean certain0, boolean isPointerArith |
723723
isDefImpl(mid, base, ind, certain0) and
724724
instr = operand.getDef() and
725-
conversionFlow(mid, instr, isPointerArith) and
725+
conversionFlow(mid, instr, isPointerArith, _) and
726726
if isPointerArith = true then certain = false else certain = certain0
727727
)
728728
or

0 commit comments

Comments
 (0)