Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 3d82308

Browse files
committed
Introduce common base class for ElementReadNode and FieldReadNode
1 parent 56f6e67 commit 3d82308

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

ql/src/semmle/go/dataflow/SSA.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ private newtype TSsaWithFields =
306306
TStep(SsaWithFields base, Field f) { exists(accessPathAux(base, f)) }
307307

308308
/**
309-
* Gets a representation of `insn` as an ssa-with-fields-and-elements value if there is one.
309+
* Gets a representation of `nd` as an ssa-with-fields value if there is one.
310310
*/
311311
private TSsaWithFields accessPath(IR::Instruction insn) {
312312
exists(SsaVariable v | insn = v.getAUse() | result = TRoot(v))

ql/src/semmle/go/dataflow/internal/DataFlowUtil.qll

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -590,14 +590,22 @@ class ReadNode extends InstructionNode {
590590
}
591591
}
592592

593+
/**
594+
* A data-flow node that reads the value of a field from a struct, or an element from an array, slice, map or string.
595+
*/
596+
class ReadFromAggregateNode extends ReadNode {
597+
/** Gets the data-flow node representing the base from which the field or element is read. */
598+
abstract Node getBase();
599+
}
600+
593601
/**
594602
* A data-flow node that reads an element of an array, map, slice or string.
595603
*/
596-
class ElementReadNode extends ReadNode {
604+
class ElementReadNode extends ReadFromAggregateNode {
597605
override IR::ElementReadInstruction insn;
598606

599607
/** Gets the data-flow node representing the base from which the element is read. */
600-
Node getBase() { result = instructionNode(insn.getBase()) }
608+
override Node getBase() { result = instructionNode(insn.getBase()) }
601609

602610
/** Gets the data-flow node representing the index of the element being read. */
603611
Node getIndex() { result = instructionNode(insn.getIndex()) }
@@ -744,11 +752,11 @@ class AddressOperationNode extends UnaryOperationNode, ExprNode {
744752
/**
745753
* A data-flow node that reads the value of a field.
746754
*/
747-
class FieldReadNode extends ReadNode {
755+
class FieldReadNode extends ReadFromAggregateNode {
748756
override IR::FieldReadInstruction insn;
749757

750758
/** Gets the base node from which the field is read. */
751-
Node getBase() { result = instructionNode(insn.getBase()) }
759+
override Node getBase() { result = instructionNode(insn.getBase()) }
752760

753761
/** Gets the field this node reads. */
754762
Field getField() { result = insn.getField() }

0 commit comments

Comments
 (0)