Skip to content

Commit 3f9ad14

Browse files
committed
Factor out common code into an abstract private class
1 parent f8a3ce7 commit 3f9ad14

File tree

1 file changed

+14
-23
lines changed

1 file changed

+14
-23
lines changed

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

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -780,16 +780,13 @@ module Public {
780780
final override Type getType() { result = this.getPreUpdateNode().getType() }
781781
}
782782

783-
/**
784-
* The value of an uninitialized local variable, viewed as a node in a data
785-
* flow graph.
786-
*/
787-
class UninitializedNode extends Node {
783+
abstract private class AbstractUninitializedNode extends Node {
788784
LocalVariable v;
785+
int indirectionIndex;
789786

790-
UninitializedNode() {
787+
AbstractUninitializedNode() {
791788
exists(SsaImpl::Definition def, SsaImpl::SourceVariable sv |
792-
def.getIndirectionIndex() = 0 and
789+
def.getIndirectionIndex() = indirectionIndex and
793790
def.getValue().asInstruction() instanceof UninitializedInstruction and
794791
SsaImpl::defToNode(this, def, sv) and
795792
v = sv.getBaseVariable().(SsaImpl::BaseIRVariable).getIRVariable().getAst()
@@ -800,29 +797,23 @@ module Public {
800797
LocalVariable getLocalVariable() { result = v }
801798
}
802799

800+
/**
801+
* The value of an uninitialized local variable, viewed as a node in a data
802+
* flow graph.
803+
*/
804+
class UninitializedNode extends AbstractUninitializedNode {
805+
UninitializedNode() { indirectionIndex = 0 }
806+
}
807+
803808
/**
804809
* The value of an uninitialized local variable behind one or more levels of
805810
* indirection, viewed as a node in a data flow graph.
806811
*
807812
* NOTE: For the direct value of the uninitialized local variable, see
808813
* `UninitializedNode`.
809814
*/
810-
class IndirectUninitializedNode extends Node {
811-
LocalVariable v;
812-
int indirectionIndex;
813-
814-
IndirectUninitializedNode() {
815-
exists(SsaImpl::Definition def, SsaImpl::SourceVariable sv |
816-
def.getIndirectionIndex() = indirectionIndex and
817-
indirectionIndex > 0 and // With `indirectionIndex` = 0, this class becomes the same as `UninitializedNode`.
818-
def.getValue().asInstruction() instanceof UninitializedInstruction and
819-
SsaImpl::defToNode(this, def, sv) and
820-
v = sv.getBaseVariable().(SsaImpl::BaseIRVariable).getIRVariable().getAst()
821-
)
822-
}
823-
824-
/** Gets the uninitialized local variable corresponding to this node. */
825-
LocalVariable getLocalVariable() { result = v }
815+
class IndirectUninitializedNode extends AbstractUninitializedNode {
816+
IndirectUninitializedNode() { indirectionIndex > 0 }
826817

827818
/** Gets the level of indirection to get to this node. */
828819
int getIndirectionIndex() { result = indirectionIndex }

0 commit comments

Comments
 (0)