Skip to content

Commit 87478d0

Browse files
committed
C++: Move 'FieldAddress' and 'conversionFlow'.
1 parent 09d74a3 commit 87478d0

2 files changed

Lines changed: 59 additions & 59 deletions

File tree

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

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,65 @@ private module Cached {
221221

222222
import Cached
223223

224+
/**
225+
* An operand that is defined by a `FieldAddressInstruction`.
226+
*/
227+
class FieldAddress extends Operand {
228+
FieldAddressInstruction fai;
229+
230+
FieldAddress() { fai = this.getDef() and not SsaImpl::ignoreOperand(this) }
231+
232+
/** Gets the field associated with this instruction. */
233+
Field getField() { result = fai.getField() }
234+
235+
/** Gets the instruction whose result provides the address of the object containing the field. */
236+
Instruction getObjectAddress() { result = fai.getObjectAddress() }
237+
238+
/** Gets the operand that provides the address of the object containing the field. */
239+
Operand getObjectAddressOperand() { result = fai.getObjectAddressOperand() }
240+
}
241+
242+
/**
243+
* Holds if `opFrom` is an operand whose value flows to the result of `instrTo`.
244+
*
245+
* `isPointerArith` is `true` if `instrTo` is a `PointerArithmeticInstruction` and `opFrom`
246+
* is the left operand.
247+
*
248+
* `additional` is `true` if the conversion is supplied by an implementation of the
249+
* `Indirection` class. It is sometimes useful to exclude such conversions.
250+
*/
251+
predicate conversionFlow(
252+
Operand opFrom, Instruction instrTo, boolean isPointerArith, boolean additional
253+
) {
254+
isPointerArith = false and
255+
(
256+
additional = false and
257+
(
258+
instrTo.(CopyValueInstruction).getSourceValueOperand() = opFrom
259+
or
260+
instrTo.(ConvertInstruction).getUnaryOperand() = opFrom
261+
or
262+
instrTo.(CheckedConvertOrNullInstruction).getUnaryOperand() = opFrom
263+
or
264+
instrTo.(InheritanceConversionInstruction).getUnaryOperand() = opFrom
265+
or
266+
exists(BuiltInInstruction builtIn |
267+
builtIn = instrTo and
268+
// __builtin_bit_cast
269+
builtIn.getBuiltInOperation() instanceof BuiltInBitCast and
270+
opFrom = builtIn.getAnOperand()
271+
)
272+
)
273+
or
274+
additional = true and
275+
SsaImpl::isAdditionalConversionFlow(opFrom, instrTo)
276+
)
277+
or
278+
isPointerArith = true and
279+
additional = false and
280+
instrTo.(PointerArithmeticInstruction).getLeftOperand() = opFrom
281+
}
282+
224283
module Public {
225284

226285
}

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

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -21,65 +21,6 @@ private import DataFlowDispatch as DataFlowDispatch
2121
import ExprNodes
2222

2323

24-
/**
25-
* An operand that is defined by a `FieldAddressInstruction`.
26-
*/
27-
class FieldAddress extends Operand {
28-
FieldAddressInstruction fai;
29-
30-
FieldAddress() { fai = this.getDef() and not SsaImpl::ignoreOperand(this) }
31-
32-
/** Gets the field associated with this instruction. */
33-
Field getField() { result = fai.getField() }
34-
35-
/** Gets the instruction whose result provides the address of the object containing the field. */
36-
Instruction getObjectAddress() { result = fai.getObjectAddress() }
37-
38-
/** Gets the operand that provides the address of the object containing the field. */
39-
Operand getObjectAddressOperand() { result = fai.getObjectAddressOperand() }
40-
}
41-
42-
/**
43-
* Holds if `opFrom` is an operand whose value flows to the result of `instrTo`.
44-
*
45-
* `isPointerArith` is `true` if `instrTo` is a `PointerArithmeticInstruction` and `opFrom`
46-
* is the left operand.
47-
*
48-
* `additional` is `true` if the conversion is supplied by an implementation of the
49-
* `Indirection` class. It is sometimes useful to exclude such conversions.
50-
*/
51-
predicate conversionFlow(
52-
Operand opFrom, Instruction instrTo, boolean isPointerArith, boolean additional
53-
) {
54-
isPointerArith = false and
55-
(
56-
additional = false and
57-
(
58-
instrTo.(CopyValueInstruction).getSourceValueOperand() = opFrom
59-
or
60-
instrTo.(ConvertInstruction).getUnaryOperand() = opFrom
61-
or
62-
instrTo.(CheckedConvertOrNullInstruction).getUnaryOperand() = opFrom
63-
or
64-
instrTo.(InheritanceConversionInstruction).getUnaryOperand() = opFrom
65-
or
66-
exists(BuiltInInstruction builtIn |
67-
builtIn = instrTo and
68-
// __builtin_bit_cast
69-
builtIn.getBuiltInOperation() instanceof BuiltInBitCast and
70-
opFrom = builtIn.getAnOperand()
71-
)
72-
)
73-
or
74-
additional = true and
75-
SsaImpl::isAdditionalConversionFlow(opFrom, instrTo)
76-
)
77-
or
78-
isPointerArith = true and
79-
additional = false and
80-
instrTo.(PointerArithmeticInstruction).getLeftOperand() = opFrom
81-
}
82-
8324
/**
8425
* A node in a data flow graph.
8526
*

0 commit comments

Comments
 (0)