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

Skip to content

Commit e2a0d62

Browse files
committed
C++: Fix 'asIndirectExpr' when the underlying instruction is a 'VariableAddressInstruction'.
1 parent 562f052 commit e2a0d62

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -722,9 +722,6 @@ private predicate convertedExprMustBeOperand(Expr e) {
722722
isFullyConvertedCall(e)
723723
}
724724

725-
/** Holds if `e` must be represented by an `IndirectOperand` node. */
726-
private predicate convertedExprMustBeIndirectOperand(Expr e) { convertedExprMustBeOperand(e) }
727-
728725
/** Holds if `node` is an `OperandNode` that should map `node.asExpr()` to `e`. */
729726
predicate exprNodeShouldBeOperand(Node node, Expr e) {
730727
e = node.asOperand().getDef().getConvertedResultExpression() and
@@ -748,9 +745,15 @@ private predicate exprNodeShouldBeIndirectOperand(IndirectOperand node, Expr e,
748745

749746
/** Holds if `node` should be an `IndirectOperand` that maps `node.asIndirectExpr()` to `e`. */
750747
private predicate indirectExprNodeShouldBeIndirectOperand(IndirectOperand node, Expr e) {
751-
e = node.getOperand().getDef().getConvertedResultExpression() and
752-
not convertedExprMustBeIndirectOperand(e) and
753-
not node instanceof ExprNode
748+
exists(Instruction instr |
749+
instr = node.getOperand().getDef() and
750+
not node instanceof ExprNode
751+
|
752+
e = instr.(VariableAddressInstruction).getAst().(Expr).getFullyConverted()
753+
or
754+
not instr instanceof VariableAddressInstruction and
755+
e = instr.getConvertedResultExpression()
756+
)
754757
}
755758

756759
/** Holds if `node` should be an instruction node that maps `node.asExpr()` to `e`. */
@@ -762,8 +765,14 @@ predicate exprNodeShouldBeInstruction(Node node, Expr e) {
762765

763766
/** Holds if `node` should be an `IndirectInstruction` that maps `node.asIndirectExpr()` to `e`. */
764767
predicate indirectExprNodeShouldBeIndirectInstruction(IndirectInstruction node, Expr e) {
765-
e = node.getInstruction().getConvertedResultExpression() and
766-
not indirectExprNodeShouldBeIndirectOperand(_, e)
768+
exists(Instruction instr |
769+
instr = node.getInstruction() and not indirectExprNodeShouldBeIndirectOperand(_, e)
770+
|
771+
e = instr.(VariableAddressInstruction).getAst().(Expr).getFullyConverted()
772+
or
773+
not instr instanceof VariableAddressInstruction and
774+
e = instr.getConvertedResultExpression()
775+
)
767776
}
768777

769778
abstract private class ExprNodeBase extends Node {
@@ -854,9 +863,7 @@ private class IndirectInstructionIndirectExprNode extends IndirectExprNodeBase,
854863
result = this.getConvertedExpr(index).getUnconverted()
855864
}
856865

857-
final override string toStringImpl() {
858-
result = this.getInstruction().getConvertedResultExpression().toString()
859-
}
866+
final override string toStringImpl() { result = super.toStringImpl() }
860867
}
861868

862869
/**

0 commit comments

Comments
 (0)