Skip to content

Commit 84797b9

Browse files
committed
C++: Refactor the address out of 'DefImpl' and into a new abstract class 'OperandBasedDef'.
1 parent cc75485 commit 84797b9

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -256,23 +256,29 @@ private predicate sourceVariableHasBaseAndIndex(SourceVariable v, BaseSourceVari
256256
}
257257

258258
abstract class DefImpl extends DefOrUseImpl {
259-
Operand address;
260259
int ind;
261260

262261
bindingset[ind]
263262
DefImpl() { any() }
264263

265-
abstract int getIndirection();
264+
override int getIndirectionIndex() { result = ind }
266265

267-
abstract Node0Impl getValue();
266+
override string toString() { result = "Def of " + this.getSourceVariable() }
267+
268+
abstract int getIndirection();
268269

269270
abstract predicate isCertain();
270271

271-
Operand getAddressOperand() { result = address }
272+
abstract Node0Impl getValue();
273+
}
272274

273-
override int getIndirectionIndex() { result = ind }
275+
abstract class OperandBasedDef extends DefImpl {
276+
Operand address;
274277

275-
override string toString() { result = "Def of " + this.getSourceVariable() }
278+
bindingset[ind]
279+
OperandBasedDef() { any() }
280+
281+
Operand getAddressOperand() { result = address }
276282

277283
override Cpp::Location getLocation() { result = this.getAddressOperand().getUse().getLocation() }
278284

@@ -281,7 +287,7 @@ abstract class DefImpl extends DefOrUseImpl {
281287
}
282288
}
283289

284-
private class DirectDef extends DefImpl, TDefImpl {
290+
private class DirectDef extends OperandBasedDef, TDefImpl {
285291
BaseSourceVariableInstruction base;
286292

287293
DirectDef() { this = TDefImpl(base, address, ind) }
@@ -295,7 +301,7 @@ private class DirectDef extends DefImpl, TDefImpl {
295301
override predicate isCertain() { isDef(true, _, address, base, _, ind) }
296302
}
297303

298-
private class IteratorDef extends DefImpl, TIteratorDef {
304+
private class IteratorDef extends OperandBasedDef, TIteratorDef {
299305
BaseSourceVariableInstruction container;
300306

301307
IteratorDef() { this = TIteratorDef(address, container, ind) }
@@ -1178,7 +1184,7 @@ class UseOrPhi extends SsaDefOrUse {
11781184
class Def extends DefOrUse {
11791185
override DefImpl defOrUse;
11801186

1181-
Operand getAddressOperand() { result = defOrUse.getAddressOperand() }
1187+
Operand getAddressOperand() { result = defOrUse.(OperandBasedDef).getAddressOperand() }
11821188

11831189
Instruction getAddress() { result = this.getAddressOperand().getDef() }
11841190

0 commit comments

Comments
 (0)