Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit df52655

Browse files
committed
C++: Fix mapping between dataflow nodes and '{Crement, Assign}Operations'.
1 parent 31b4dda commit df52655

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -821,9 +821,27 @@ private predicate exprNodeShouldBeIndirectOutNode(IndirectArgumentOutNode node,
821821

822822
/** Holds if `node` should be an instruction node that maps `node.asExpr()` to `e`. */
823823
predicate exprNodeShouldBeInstruction(Node node, Expr e) {
824-
e = node.asInstruction().getConvertedResultExpression() and
825824
not exprNodeShouldBeOperand(_, e) and
826-
not exprNodeShouldBeIndirectOutNode(_, e)
825+
not exprNodeShouldBeIndirectOutNode(_, e) and
826+
(
827+
e = node.asInstruction().getConvertedResultExpression()
828+
or
829+
// The instruction that contains the result of an `AssignOperation` is
830+
// the unloaded left operand (see the comments in `TranslatedAssignOperation`).
831+
// That means that for cases like
832+
// ```cpp
833+
// int x = ...;
834+
// x += 1;
835+
// ```
836+
// the result of `x += 1` is the `VariableAddressInstruction` that represents `x`. But
837+
// that instruction doesn't receive the flow from this `AssignOperation`. So instead we
838+
// map the operation to the `AddInstruction`.
839+
node.asInstruction().getAst() = e.(AssignOperation)
840+
or
841+
// Same story for `CrementOperation`s (cf. the comments in the subclasses
842+
// of `TranslatedCrementOperation`).
843+
node.asInstruction().getAst() = e.(CrementOperation)
844+
)
827845
}
828846

829847
/** Holds if `node` should be an `IndirectInstruction` that maps `node.asIndirectExpr()` to `e`. */

0 commit comments

Comments
 (0)