Skip to content

Commit 490156d

Browse files
committed
C++: Remove the 'isIndirection' predicate on 'SourceVariable' and move the rootdef of 'getIRVariable' into the two subclasses.
1 parent 05900cd commit 490156d

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

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

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,27 @@ private module SourceVariables {
1414
abstract class SourceVariable extends TSourceVariable {
1515
IRVariable var;
1616

17-
IRVariable getIRVariable() { result = var }
18-
1917
abstract string toString();
20-
21-
predicate isIndirection() { none() }
2218
}
2319

24-
private class SourceIRVariable extends SourceVariable, TSourceIRVariable {
20+
class SourceIRVariable extends SourceVariable, TSourceIRVariable {
2521
SourceIRVariable() { this = TSourceIRVariable(var) }
2622

23+
IRVariable getIRVariable() { result = var }
24+
2725
override string toString() { result = this.getIRVariable().toString() }
2826
}
2927

30-
private class SourceIRVariableIndirection extends SourceVariable, TSourceIRVariableIndirection {
28+
class SourceIRVariableIndirection extends SourceVariable, TSourceIRVariableIndirection {
3129
InitializeIndirectionInstruction init;
3230

3331
SourceIRVariableIndirection() {
3432
this = TSourceIRVariableIndirection(init) and var = init.getIRVariable()
3533
}
3634

37-
override string toString() { result = "*" + this.getIRVariable().toString() }
35+
IRVariable getUnderlyingIRVariable() { result = var }
3836

39-
override predicate isIndirection() { any() }
37+
override string toString() { result = "*" + this.getUnderlyingIRVariable().toString() }
4038
}
4139
}
4240

@@ -120,8 +118,7 @@ private class ExplicitDef extends Def, TExplicitDef {
120118
override SourceVariable getSourceVariable() {
121119
exists(VariableInstruction var |
122120
explicitWrite(_, this.getInstruction(), var) and
123-
result.getIRVariable() = var.getIRVariable() and
124-
not result.isIndirection()
121+
result.(SourceIRVariable).getIRVariable() = var.getIRVariable()
125122
)
126123
}
127124

@@ -132,11 +129,11 @@ private class ParameterDef extends Def, TInitializeParam {
132129
ParameterDef() { this = TInitializeParam(store) }
133130

134131
override SourceVariable getSourceVariable() {
135-
result.getIRVariable() = store.(InitializeParameterInstruction).getIRVariable() and
136-
not result.isIndirection()
132+
result.(SourceIRVariable).getIRVariable() =
133+
store.(InitializeParameterInstruction).getIRVariable()
137134
or
138-
result.getIRVariable() = store.(InitializeIndirectionInstruction).getIRVariable() and
139-
result.isIndirection()
135+
result.(SourceIRVariableIndirection).getUnderlyingIRVariable() =
136+
store.(InitializeIndirectionInstruction).getIRVariable()
140137
}
141138

142139
override predicate isCertain() { any() }
@@ -166,12 +163,9 @@ private class ExplicitUse extends Use, TExplicitUse {
166163
override SourceVariable getSourceVariable() {
167164
exists(VariableInstruction var |
168165
use.getDef() = var and
169-
result.getIRVariable() = var.getIRVariable() and
170-
(
171-
if use.getUse() instanceof ReadSideEffectInstruction
172-
then result.isIndirection()
173-
else not result.isIndirection()
174-
)
166+
if use.getUse() instanceof ReadSideEffectInstruction
167+
then result.(SourceIRVariableIndirection).getUnderlyingIRVariable() = var.getIRVariable()
168+
else result.(SourceIRVariable).getIRVariable() = var.getIRVariable()
175169
)
176170
}
177171
}
@@ -182,8 +176,7 @@ private class ReturnParameterIndirection extends Use, TReturnParamIndirection {
182176
override SourceVariable getSourceVariable() {
183177
exists(ReturnIndirectionInstruction ret |
184178
returnParameterIndirection(use, ret) and
185-
result.getIRVariable() = ret.getIRVariable() and
186-
result.isIndirection()
179+
result.(SourceIRVariableIndirection).getUnderlyingIRVariable() = ret.getIRVariable()
187180
)
188181
}
189182
}

0 commit comments

Comments
 (0)