Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7545fe7

Browse files
committed
Java, C#: Refactor implicitSsaDefSign in sign analysis
1 parent 37fc1d6 commit 7545fe7

4 files changed

Lines changed: 31 additions & 12 deletions

File tree

csharp/ql/src/semmle/code/csharp/dataflow/internal/rangeanalysis/SignAnalysisCommon.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,13 @@ private Sign ssaDefSign(SsaVariable v) {
245245
)
246246
}
247247

248+
/** Returns the sign of implicit SSA definition `v`. */
249+
private Sign implicitSsaDefSign(SsaVariable v) {
250+
result = fieldSign(getImplicitSsaDeclaration(v))
251+
or
252+
anySign(result) and nonFieldImplicitSsaDefinition(v)
253+
}
254+
248255
/** Gets a possible sign for `e`. */
249256
cached
250257
Sign exprSign(Expr e) {

csharp/ql/src/semmle/code/csharp/dataflow/internal/rangeanalysis/SignAnalysisSpecific.qll

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,14 @@ private module Impl {
122122
)
123123
}
124124

125-
/** Returns the sign of implicit SSA definition `v`. */
126-
Sign implicitSsaDefSign(Ssa::ImplicitDefinition v) {
127-
result = fieldSign(v.getSourceVariable().getAssignable())
128-
or
129-
anySign(result) and not v.getSourceVariable().getAssignable() instanceof Field
125+
/** Gets the variable underlying the implicit SSA variable `v`. */
126+
Declaration getImplicitSsaDeclaration(Ssa::ImplicitDefinition v) {
127+
result = v.getSourceVariable().getAssignable()
128+
}
129+
130+
/** Holds if the variable underlying the implicit SSA variable `v` is not a field. */
131+
predicate nonFieldImplicitSsaDefinition(Ssa::ImplicitDefinition v) {
132+
not getImplicitSsaDeclaration(v) instanceof Field
130133
}
131134

132135
/** Gets a possible sign for `f`. */

java/ql/src/semmle/code/java/dataflow/internal/rangeanalysis/SignAnalysisCommon.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,13 @@ private Sign ssaDefSign(SsaVariable v) {
245245
)
246246
}
247247

248+
/** Returns the sign of implicit SSA definition `v`. */
249+
private Sign implicitSsaDefSign(SsaVariable v) {
250+
result = fieldSign(getImplicitSsaDeclaration(v))
251+
or
252+
anySign(result) and nonFieldImplicitSsaDefinition(v)
253+
}
254+
248255
/** Gets a possible sign for `e`. */
249256
cached
250257
Sign exprSign(Expr e) {

java/ql/src/semmle/code/java/dataflow/internal/rangeanalysis/SignAnalysisSpecific.qll

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,15 @@ private module Impl {
115115
)
116116
}
117117

118-
/** Returns the sign of implicit SSA definition `v`. */
119-
Sign implicitSsaDefSign(SsaVariable v) {
120-
result = fieldSign(v.(SsaImplicitUpdate).getSourceVariable().getVariable())
121-
or
122-
result = fieldSign(v.(SsaImplicitInit).getSourceVariable().getVariable())
123-
or
124-
anySign(result) and exists(Parameter p | v.(SsaImplicitInit).isParameterDefinition(p))
118+
/** Gets the variable underlying the implicit SSA variable `v`. */
119+
Variable getImplicitSsaDeclaration(SsaVariable v) {
120+
result = v.(SsaImplicitUpdate).getSourceVariable().getVariable() or
121+
result = v.(SsaImplicitInit).getSourceVariable().getVariable()
122+
}
123+
124+
/** Holds if the variable underlying the implicit SSA variable `v` is not a field. */
125+
predicate nonFieldImplicitSsaDefinition(SsaImplicitInit v) {
126+
exists(Parameter p | v.isParameterDefinition(p))
125127
}
126128

127129
/** Gets a possible sign for `f`. */

0 commit comments

Comments
 (0)