Skip to content

Commit be24535

Browse files
authored
Merge pull request #21458 from github/jeongsoolee09/add-getIndirectionIndex
Add `IndirectUninitializedNode` and related helper predicates
2 parents 9a4bc69 + ee00b98 commit be24535

File tree

2 files changed

+46
-7
lines changed

2 files changed

+46
-7
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: feature
3+
---
4+
* Added a new data flow node, `IndirectUninitializedNode`, that represents uninitialized local variables behind a number of indirections.

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

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,25 @@ module Public {
617617
*/
618618
LocalVariable asUninitialized() { result = this.(UninitializedNode).getLocalVariable() }
619619

620+
/**
621+
* Gets the uninitialized local variable corresponding to this node behind
622+
* `index` number of indirections, if any.
623+
*/
624+
LocalVariable asIndirectUninitialized(int index) {
625+
exists(IndirectUninitializedNode indirectUninitializedNode |
626+
this = indirectUninitializedNode and
627+
indirectUninitializedNode.getIndirectionIndex() = index
628+
|
629+
result = indirectUninitializedNode.getLocalVariable()
630+
)
631+
}
632+
633+
/**
634+
* Gets the uninitialized local variable corresponding to this node behind
635+
* a number indirections, if any.
636+
*/
637+
LocalVariable asIndirectUninitialized() { result = this.asIndirectUninitialized(_) }
638+
620639
/**
621640
* Gets the positional parameter corresponding to the node that represents
622641
* the value of the parameter after `index` number of loads, if any. For
@@ -761,16 +780,13 @@ module Public {
761780
final override Type getType() { result = this.getPreUpdateNode().getType() }
762781
}
763782

764-
/**
765-
* The value of an uninitialized local variable, viewed as a node in a data
766-
* flow graph.
767-
*/
768-
class UninitializedNode extends Node {
783+
abstract private class AbstractUninitializedNode extends Node {
769784
LocalVariable v;
785+
int indirectionIndex;
770786

771-
UninitializedNode() {
787+
AbstractUninitializedNode() {
772788
exists(SsaImpl::Definition def, SsaImpl::SourceVariable sv |
773-
def.getIndirectionIndex() = 0 and
789+
def.getIndirectionIndex() = indirectionIndex and
774790
def.getValue().asInstruction() instanceof UninitializedInstruction and
775791
SsaImpl::defToNode(this, def, sv) and
776792
v = sv.getBaseVariable().(SsaImpl::BaseIRVariable).getIRVariable().getAst()
@@ -781,6 +797,25 @@ module Public {
781797
LocalVariable getLocalVariable() { result = v }
782798
}
783799

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+
808+
/**
809+
* The value of an uninitialized local variable behind one or more levels of
810+
* indirection, viewed as a node in a data flow graph.
811+
*/
812+
class IndirectUninitializedNode extends AbstractUninitializedNode {
813+
IndirectUninitializedNode() { indirectionIndex > 0 }
814+
815+
/** Gets the indirection index of this node. */
816+
int getIndirectionIndex() { result = indirectionIndex }
817+
}
818+
784819
/**
785820
* The value of a parameter at function entry, viewed as a node in a data
786821
* flow graph. This includes both explicit parameters such as `x` in `f(x)`

0 commit comments

Comments
 (0)