Skip to content

Commit a747ffc

Browse files
committed
C++: Address definitions should also handle ssa variables that are calls.
1 parent 79919d3 commit a747ffc

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

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

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ predicate hasRawIndirectInstruction(Instruction instr, int indirectionIndex) {
104104

105105
cached
106106
private newtype TDefImpl =
107-
TDefAddressImpl(BaseIRVariable v) or
107+
TDefAddressImpl(BaseSourceVariable v) or
108108
TDirectDefImpl(Operand address, int indirectionIndex) {
109109
isDef(_, _, address, _, _, indirectionIndex)
110110
} or
@@ -325,9 +325,9 @@ private Instruction getInitializationTargetAddress(IRVariable v) {
325325
)
326326
}
327327

328-
/** An initial definition of an `IRVariable`'s address. */
329-
private class DefAddressImpl extends DefImpl, TDefAddressImpl {
330-
BaseIRVariable v;
328+
/** An initial definition of an SSA variable address. */
329+
abstract private class DefAddressImpl extends DefImpl, TDefAddressImpl {
330+
BaseSourceVariable v;
331331

332332
DefAddressImpl() {
333333
this = TDefAddressImpl(v) and
@@ -342,6 +342,19 @@ private class DefAddressImpl extends DefImpl, TDefAddressImpl {
342342

343343
final override Node0Impl getValue() { none() }
344344

345+
override Cpp::Location getLocation() { result = v.getLocation() }
346+
347+
final override SourceVariable getSourceVariable() {
348+
result.getBaseVariable() = v and
349+
result.getIndirection() = 0
350+
}
351+
352+
final override BaseSourceVariable getBaseSourceVariable() { result = v }
353+
}
354+
355+
private class DefVariableAddressImpl extends DefAddressImpl {
356+
override BaseIRVariable v;
357+
345358
final override predicate hasIndexInBlock(IRBlock block, int index) {
346359
exists(IRVariable var | var = v.getIRVariable() |
347360
block.getInstruction(index) = getInitializationTargetAddress(var)
@@ -353,15 +366,14 @@ private class DefAddressImpl extends DefImpl, TDefAddressImpl {
353366
index = 0
354367
)
355368
}
369+
}
356370

357-
override Cpp::Location getLocation() { result = v.getIRVariable().getLocation() }
371+
private class DefCallAddressImpl extends DefAddressImpl {
372+
override BaseCallVariable v;
358373

359-
final override SourceVariable getSourceVariable() {
360-
result.getBaseVariable() = v and
361-
result.getIndirection() = 0
374+
final override predicate hasIndexInBlock(IRBlock block, int index) {
375+
block.getInstruction(index) = v.getCallInstruction()
362376
}
363-
364-
final override BaseSourceVariable getBaseSourceVariable() { result = v }
365377
}
366378

367379
private class DirectDef extends DefImpl, TDirectDefImpl {

0 commit comments

Comments
 (0)