Skip to content

Commit 889925b

Browse files
committed
C++: Modify the API to not expose dataflow nodes.
1 parent de0bb48 commit 889925b

File tree

1 file changed

+35
-5
lines changed
  • cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal

1 file changed

+35
-5
lines changed

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

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,12 +1140,33 @@ class Definition extends SsaImpl::Definition {
11401140
not result instanceof PhiNode
11411141
}
11421142

1143-
/** Gets a `Node` that represents a use of this definition. */
1144-
Node getAUse() {
1143+
/** Gets an `Operand` that represents a use of this definition. */
1144+
Operand getAUse() {
11451145
exists(SourceVariable sv, IRBlock bb, int i, UseImpl use |
11461146
ssaDefReachesRead(sv, this, bb, i) and
11471147
use.hasIndexInBlock(bb, i, sv) and
1148-
result = use.getNode()
1148+
result = use.getNode().asOperand()
1149+
)
1150+
}
1151+
1152+
/**
1153+
* Gets an `Operand` that represents an indirect use of this definition.
1154+
*
1155+
* The use is indirect because the operand represents a pointer that points
1156+
* to the value written by this definition. For example in:
1157+
* ```cpp
1158+
* 1. int x = 42;
1159+
* 2. int* p = &x;
1160+
* ```
1161+
* There is an `ExplicitDefinition` corresponding to `x = 42` on line 1 and
1162+
* the definition has an indirect use on line 2 because `&x` points to the
1163+
* value that was defined by the definition.
1164+
*/
1165+
Operand getAnIndirectUse(int indirectionIndex) {
1166+
exists(SourceVariable sv, IRBlock bb, int i, UseImpl use |
1167+
ssaDefReachesRead(sv, this, bb, i) and
1168+
use.hasIndexInBlock(bb, i, sv) and
1169+
result = use.getNode().asIndirectOperand(indirectionIndex)
11491170
)
11501171
}
11511172

@@ -1195,9 +1216,18 @@ class ExplicitDefinition extends Definition, SsaImpl::WriteDefinition {
11951216
}
11961217

11971218
/**
1198-
* Gets the `Node` computing the value that is written by this SSA definition.
1219+
* Gets the `Instruction` computing the value that is written to the
1220+
* associated SSA variable by this SSA definition.
1221+
*
1222+
* If `this.getIndirectionIndex() = 0` (i.e., if `this` is an instance of
1223+
* `DirectExplicitDefinition`) then the SSA variable is present in the source
1224+
* code.
1225+
* However, if `this.getIndirectionIndex() > 0` (i.e., if `this` is an
1226+
* instance of `IndirectExplicitDefinition`) then the SSA variable associated
1227+
* with this definition represents the memory pointed to by a variable in the
1228+
* source code.
11991229
*/
1200-
Node getAssignedValue() { result.asInstruction() = def.getValue().asInstruction() }
1230+
Instruction getAssignedInstruction() { result = def.getValue().asInstruction() }
12011231
}
12021232

12031233
/**

0 commit comments

Comments
 (0)