diff --git a/cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll b/cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll index 06bb08093f0..cc4ae90faf9 100644 --- a/cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll +++ b/cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll @@ -49,11 +49,7 @@ class Node0Impl extends TIRDataFlowNode0 { DataFlowType getType() { none() } // overridden in subclasses /** Gets the instruction corresponding to this node, if any. */ - Instruction asInstruction() { - result = this.(InstructionNode0).getInstruction() - or - result = Ssa::getIRRepresentationOfOperand(this.(SingleUseOperandNode0).getOperand()) - } + Instruction asInstruction() { result = this.(InstructionNode0).getInstruction() } /** Gets the operands corresponding to this node, if any. */ Operand asOperand() { result = this.(OperandNode0).getOperand() } @@ -78,11 +74,9 @@ class Node0Impl extends TIRDataFlowNode0 { /** * An instruction, viewed as a node in a data flow graph. */ -class InstructionNode0 extends Node0Impl, TInstructionNode0 { +abstract class InstructionNode0 extends Node0Impl { Instruction instr; - InstructionNode0() { this = TInstructionNode0(instr) } - /** Gets the instruction corresponding to this node. */ Instruction getInstruction() { result = instr } @@ -101,6 +95,25 @@ class InstructionNode0 extends Node0Impl, TInstructionNode0 { } } +/** + * An instruction without an operand that is used only once, viewed as a node in a data flow graph. + */ +private class InstructionInstructionNode0 extends InstructionNode0, TInstructionNode0 { + InstructionInstructionNode0() { this = TInstructionNode0(instr) } +} + +/** + * An instruction with an operand that is used only once, viewed as a node in a data flow graph. + */ +private class SingleUseOperandInstructionNode0 extends InstructionNode0, TSingleUseOperandNode0 { + SingleUseOperandInstructionNode0() { + exists(Operand op | + this = TSingleUseOperandNode0(op) and + instr = Ssa::getIRRepresentationOfOperand(op) + ) + } +} + /** * An operand, viewed as a node in a data flow graph. */ @@ -124,14 +137,14 @@ abstract class OperandNode0 extends Node0Impl { /** * An operand that is used multiple times, viewed as a node in a data flow graph. */ -class MultipleUseOperandNode0 extends OperandNode0, TMultipleUseOperandNode0 { +private class MultipleUseOperandNode0 extends OperandNode0, TMultipleUseOperandNode0 { MultipleUseOperandNode0() { this = TMultipleUseOperandNode0(op) } } /** * An operand that is used only once, viewed as a node in a data flow graph. */ -class SingleUseOperandNode0 extends OperandNode0, TSingleUseOperandNode0 { +private class SingleUseOperandNode0 extends OperandNode0, TSingleUseOperandNode0 { SingleUseOperandNode0() { this = TSingleUseOperandNode0(op) } } diff --git a/cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll b/cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll index 7c49ea8c353..d8bcc2d2a76 100644 --- a/cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll +++ b/cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll @@ -383,13 +383,10 @@ private class Node0 extends Node, TNode0 { * An instruction, viewed as a node in a data flow graph. */ class InstructionNode extends Node0 { + override InstructionNode0 node; Instruction instr; - InstructionNode() { - node.(InstructionNode0).getInstruction() = instr - or - Ssa::getIRRepresentationOfOperand(node.(SingleUseOperandNode0).getOperand()) = instr - } + InstructionNode() { instr = node.getInstruction() } /** Gets the instruction corresponding to this node. */ Instruction getInstruction() { result = instr }