Skip to content

Commit 78b7e12

Browse files
committed
C++: Make 'DefImpl' and 'useImpl' abstract.
1 parent 5d417d7 commit 78b7e12

2 files changed

Lines changed: 54 additions & 22 deletions

File tree

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

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -192,21 +192,22 @@ private predicate sourceVariableHasBaseAndIndex(SourceVariable v, BaseSourceVari
192192
v.getIndirection() = ind
193193
}
194194

195-
class DefImpl extends DefOrUseImpl, TDefImpl {
195+
abstract class DefImpl extends DefOrUseImpl {
196196
Operand address;
197197
int ind;
198198

199-
DefImpl() { this = TDefImpl(address, ind) }
199+
bindingset[ind]
200+
DefImpl() { any() }
200201

201-
override BaseSourceVariableInstruction getBase() { isDef(_, _, address, result, _, _) }
202+
abstract int getIndirection();
202203

203-
Operand getAddressOperand() { result = address }
204+
abstract Node0Impl getValue();
204205

205-
int getIndirection() { isDef(_, _, address, _, result, ind) }
206+
abstract predicate isCertain();
206207

207-
override int getIndirectionIndex() { result = ind }
208+
Operand getAddressOperand() { result = address }
208209

209-
Node0Impl getValue() { isDef(_, result, address, _, _, _) }
210+
override int getIndirectionIndex() { result = ind }
210211

211212
override string toString() { result = "DefImpl" }
212213

@@ -217,15 +218,28 @@ class DefImpl extends DefOrUseImpl, TDefImpl {
217218
final override predicate hasIndexInBlock(IRBlock block, int index) {
218219
this.getAddressOperand().getUse() = block.getInstruction(index)
219220
}
221+
}
222+
223+
private class DirectDef extends DefImpl, TDefImpl {
224+
DirectDef() { this = TDefImpl(address, ind) }
225+
226+
override BaseSourceVariableInstruction getBase() { isDef(_, _, address, result, _, _) }
227+
228+
override int getIndirection() { isDef(_, _, address, _, result, ind) }
229+
230+
override Node0Impl getValue() { isDef(_, result, address, _, _, _) }
231+
232+
override predicate isCertain() { isDef(true, _, address, _, _, ind) }
220233

221234
predicate isCertain() { isDef(true, _, address, _, _, ind) }
222235
}
223236

224-
class UseImpl extends DefOrUseImpl, TUseImpl {
237+
abstract class UseImpl extends DefOrUseImpl {
225238
Operand operand;
226239
int ind;
227240

228-
UseImpl() { this = TUseImpl(operand, ind) }
241+
bindingset[ind]
242+
UseImpl() { any() }
229243

230244
Operand getOperand() { result = operand }
231245

@@ -239,13 +253,21 @@ class UseImpl extends DefOrUseImpl, TUseImpl {
239253

240254
final override Cpp::Location getLocation() { result = operand.getLocation() }
241255

242-
final int getIndirection() { isUse(_, operand, _, result, ind) }
243-
244256
override int getIndirectionIndex() { result = ind }
245257

258+
abstract int getIndirection();
259+
260+
abstract predicate isCertain();
261+
}
262+
263+
private class DirectUse extends UseImpl, TUseImpl {
264+
DirectUse() { this = TUseImpl(operand, ind) }
265+
266+
override int getIndirection() { isUse(_, operand, _, result, ind) }
267+
246268
override BaseSourceVariableInstruction getBase() { isUse(_, operand, result, _, ind) }
247269

248-
predicate isCertain() { isUse(true, operand, _, _, ind) }
270+
override predicate isCertain() { isUse(true, operand, _, _, ind) }
249271
}
250272

251273
/**

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

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,16 @@ abstract private class DefOrUseImpl extends TDefOrUseImpl {
6363
final SourceVariable getSourceVariable() {
6464
result.getBaseVariable() = this.getBaseSourceVariable()
6565
}
66+
67+
abstract predicate isCertain();
6668
}
6769

68-
class DefImpl extends DefOrUseImpl, TDefImpl {
70+
abstract class DefImpl extends DefOrUseImpl {
6971
Operand address;
7072

71-
DefImpl() { this = TDefImpl(address) }
72-
73-
override BaseSourceVariableInstruction getBase() { isDef(_, _, address, result, _, _) }
74-
7573
Operand getAddressOperand() { result = address }
7674

77-
Node0Impl getValue() { isDef(_, result, address, _, _, _) }
75+
abstract Node0Impl getValue();
7876

7977
override string toString() { result = address.toString() }
8078

@@ -85,15 +83,23 @@ class DefImpl extends DefOrUseImpl, TDefImpl {
8583
final override predicate hasIndexInBlock(IRBlock block, int index) {
8684
this.getAddressOperand().getUse() = block.getInstruction(index)
8785
}
86+
}
87+
88+
private class DirectDef extends DefImpl, TDefImpl {
89+
DirectDef() { this = TDefImpl(address) }
90+
91+
override BaseSourceVariableInstruction getBase() { isDef(_, _, address, result, _, _) }
92+
93+
override Node0Impl getValue() { isDef(_, result, address, _, _, _) }
94+
95+
override predicate isCertain() { isDef(true, _, address, _, _, _) }
8896

8997
predicate isCertain() { isDef(true, _, address, _, _, _) }
9098
}
9199

92-
class UseImpl extends DefOrUseImpl, TUseImpl {
100+
abstract class UseImpl extends DefOrUseImpl {
93101
Operand operand;
94102

95-
UseImpl() { this = TUseImpl(operand) }
96-
97103
Operand getOperand() { result = operand }
98104

99105
override string toString() { result = operand.toString() }
@@ -105,10 +111,14 @@ class UseImpl extends DefOrUseImpl, TUseImpl {
105111
final override IRBlock getBlock() { result = operand.getUse().getBlock() }
106112

107113
final override Cpp::Location getLocation() { result = operand.getLocation() }
114+
}
115+
116+
private class DirectUse extends UseImpl, TUseImpl {
117+
DirectUse() { this = TUseImpl(operand) }
108118

109119
override BaseSourceVariableInstruction getBase() { isUse(_, operand, result, _, _) }
110120

111-
predicate isCertain() { isUse(true, operand, _, _, _) }
121+
override predicate isCertain() { isUse(true, operand, _, _, _) }
112122
}
113123

114124
private module SsaInput implements SsaImplCommon::InputSig {

0 commit comments

Comments
 (0)