Skip to content

Commit 5bc602a

Browse files
committed
C++: Ensure that we don't create a result for 'asExpr' on an instruction node if a result also exists for an operand node (and vice versa).
1 parent 5c43a0b commit 5bc602a

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,11 +1394,21 @@ abstract private class ExprNodeBase extends Node {
13941394
final Expr getExpr(int n) { result = this.getConvertedExpr(n).getUnconverted() }
13951395
}
13961396

1397+
/**
1398+
* Holds if there exists a dataflow node whose `asExpr(n)` should evaluate
1399+
* to `e`.
1400+
*/
1401+
private predicate exprNodeShouldBe(Expr e, int n) {
1402+
exprNodeShouldBeInstruction(_, e, n) or
1403+
exprNodeShouldBeOperand(_, e, n) or
1404+
exprNodeShouldBeIndirectOutNode(_, e, n)
1405+
}
1406+
13971407
private class InstructionExprNode extends ExprNodeBase, InstructionNode {
13981408
InstructionExprNode() {
13991409
exists(Expr e, int n |
14001410
exprNodeShouldBeInstruction(this, e, n) and
1401-
not exprNodeShouldBeInstruction(_, e, n + 1)
1411+
not exprNodeShouldBe(e, n + 1)
14021412
)
14031413
}
14041414

@@ -1409,7 +1419,7 @@ private class OperandExprNode extends ExprNodeBase, OperandNode {
14091419
OperandExprNode() {
14101420
exists(Expr e, int n |
14111421
exprNodeShouldBeOperand(this, e, n) and
1412-
not exprNodeShouldBeOperand(_, e, n + 1)
1422+
not exprNodeShouldBe(e, n + 1)
14131423
)
14141424
}
14151425

0 commit comments

Comments
 (0)