Skip to content

Commit 7916616

Browse files
committed
C++: Fix duplication for indirect exprs similar to how we fixed it in #15410.
1 parent 4e18cca commit 7916616

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1484,12 +1484,17 @@ private module IndirectNodeToIndirectExpr<IndirectNodeToIndirectExprSig Sig> {
14841484
indirectNodeHasIndirectExpr(node, e, n, indirectionIndex) and
14851485
not exists(Expr conv, int adjustedIndirectionIndex |
14861486
adjustForReference(e, indirectionIndex, conv, adjustedIndirectionIndex) and
1487-
indirectNodeHasIndirectExpr(_, conv, n + 1, adjustedIndirectionIndex)
1487+
indirectExprNodeShouldBe(conv, n + 1, adjustedIndirectionIndex)
14881488
)
14891489
)
14901490
}
14911491
}
14921492

1493+
private predicate indirectExprNodeShouldBe(Expr e, int n, int indirectionIndex) {
1494+
indirectExprNodeShouldBeIndirectOperand(_, e, n, indirectionIndex) or
1495+
indirectExprNodeShouldBeIndirectInstruction(_, e, n, indirectionIndex)
1496+
}
1497+
14931498
private module IndirectOperandIndirectExprNodeImpl implements IndirectNodeToIndirectExprSig {
14941499
class IndirectNode = IndirectOperand;
14951500

cpp/ql/test/library-tests/dataflow/asExpr/test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ void take_const_ref_int(const int &);
22

33
void test_materialize_temp_int()
44
{
5-
take_const_ref_int(42); // $ asExpr=42 numberOfNodes="42: 2" asIndirectExpr=42 numberOfIndirectNodes="42: 2"
5+
take_const_ref_int(42); // $ asExpr=42 numberOfNodes="42: 2" asIndirectExpr=42
66
}
77

88
struct A {};
@@ -11,7 +11,7 @@ A get();
1111
void take_const_ref(const A &);
1212

1313
void test1(){
14-
take_const_ref(get()); // $ asExpr="call to get" numberOfNodes="call to get: 2" asIndirectExpr="call to get" numberOfIndirectNodes="call to get: 2"
14+
take_const_ref(get()); // $ asExpr="call to get" numberOfNodes="call to get: 2" asIndirectExpr="call to get"
1515
}
1616

1717
void take_ref(A &);

0 commit comments

Comments
 (0)