Skip to content

Commit c54dc49

Browse files
committed
C++: Improve 'toString' on the 'InitializeGroup' instruction.
1 parent b185c67 commit c54dc49

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/Instruction.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,6 +2167,18 @@ class ChiInstruction extends Instruction {
21672167
*/
21682168
class InitializeGroupInstruction extends Instruction {
21692169
InitializeGroupInstruction() { this.getOpcode() instanceof Opcode::InitializeGroup }
2170+
2171+
/**
2172+
* Gets an `IRVariable` whose memory is initialized by this instruction, if any.
2173+
* Note: Allocations that are not represented as `IRVariable`s (such as
2174+
* dynamic allocations) are not returned by this predicate even if this
2175+
* instruction initializes such memory.
2176+
*/
2177+
final IRVariable getAnIRVariable() { result = Construction::getAnInitializeGroupVariable(this) }
2178+
2179+
final override string getImmediateString() {
2180+
result = strictconcat(this.getAnIRVariable().toString(), ",")
2181+
}
21702182
}
21712183

21722184
/**

cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/internal/SSAConstruction.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,14 @@ private module Cached {
263263
)
264264
}
265265

266+
cached
267+
IRVariable getAnInitializeGroupVariable(InitializeGroupInstruction init) {
268+
exists(Alias::VariableGroup vg |
269+
init = initializeGroup(vg) and
270+
result = vg.getAnAllocation().getABaseInstruction().(VariableInstruction).getIRVariable()
271+
)
272+
}
273+
266274
/**
267275
* Holds if `instr` is part of a cycle in the operand graph that doesn't go
268276
* through a phi instruction and therefore should be impossible.

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/IRConstruction.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,8 @@ predicate hasUnreachedInstruction(IRFunction func) {
407407
)
408408
}
409409

410+
IRVariable getAnInitializeGroupVariable(InitializeGroupInstruction instr) { none() }
411+
410412
import CachedForDebugging
411413

412414
cached

cpp/ql/lib/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/SSAConstruction.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ private module Cached {
263263
)
264264
}
265265

266+
cached
267+
IRVariable getAnInitializeGroupVariable(InitializeGroupInstruction instr) { none() }
268+
266269
/**
267270
* Holds if `instr` is part of a cycle in the operand graph that doesn't go
268271
* through a phi instruction and therefore should be impossible.

0 commit comments

Comments
 (0)