Skip to content

Commit cf162aa

Browse files
committed
C++: Add an explicit definition of the address of an IRVariable.
1 parent 84797b9 commit cf162aa

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

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

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ predicate hasRawIndirectInstruction(Instruction instr, int indirectionIndex) {
103103

104104
cached
105105
private newtype TDefOrUseImpl =
106+
TDefAddressImpl(BaseIRVariable v) or
106107
TDefImpl(BaseSourceVariableInstruction base, Operand address, int indirectionIndex) {
107108
isDef(_, _, address, base, _, indirectionIndex)
108109
} or
@@ -272,7 +273,41 @@ abstract class DefImpl extends DefOrUseImpl {
272273
abstract Node0Impl getValue();
273274
}
274275

275-
abstract class OperandBasedDef extends DefImpl {
276+
/** An initial definition of an `IRVariable`'s address. */
277+
private class DefAddressImpl extends DefImpl, TDefAddressImpl {
278+
BaseIRVariable v;
279+
280+
DefAddressImpl() {
281+
this = TDefAddressImpl(v) and
282+
ind = 0
283+
}
284+
285+
final override int getIndirection() { result = 0 }
286+
287+
final override predicate isCertain() { any() }
288+
289+
final override Node0Impl getValue() { none() }
290+
291+
final override predicate hasIndexInBlock(IRBlock block, int index) {
292+
block = v.getIRVariable().getEnclosingIRFunction().getEntryBlock() and
293+
index = 0
294+
}
295+
296+
override Cpp::Location getLocation() { result = v.getIRVariable().getLocation() }
297+
298+
final override SourceVariable getSourceVariable() {
299+
result.getBaseVariable() = v and
300+
result.getIndirection() = 0
301+
}
302+
303+
final override BaseSourceVariableInstruction getBase() { none() }
304+
}
305+
306+
/**
307+
* An SSA definition that has an associated `Operand` representing the address
308+
* that is being written to.
309+
*/
310+
abstract private class OperandBasedDef extends DefImpl {
276311
Operand address;
277312

278313
bindingset[ind]

0 commit comments

Comments
 (0)