Skip to content

Commit 3eb55dd

Browse files
authored
Merge pull request #4704 from tamasvajk/feature/stats2
C#: Update DB stats file
2 parents 1142a79 + ecfa66e commit 3eb55dd

File tree

10 files changed

+10686
-10425
lines changed

10 files changed

+10686
-10425
lines changed

csharp/ql/src/Language Abuse/UselessTypeTest.ql

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@
1212

1313
import csharp
1414

15+
pragma[noinline]
16+
private predicate isTypePattern(IsExpr ie, ValueOrRefType t, ValueOrRefType ct) {
17+
t = ie.getExpr().getType() and
18+
ct = ie.getPattern().(TypePatternExpr).getCheckedType()
19+
}
20+
1521
from IsExpr ie, ValueOrRefType t, ValueOrRefType ct
1622
where
17-
t = ie.getExpr().getType() and
18-
ct = ie.getPattern().(TypePatternExpr).getCheckedType() and
23+
isTypePattern(ie, t, ct) and
1924
ct = t.getABaseType+()
2025
select ie,
2126
"There is no need to test whether an instance of $@ is also an instance of $@ - it always is.", t,

csharp/ql/src/Language Abuse/UselessUpcast.ql

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,21 @@ class ExplicitUpcast extends ExplicitCast {
8686
src != dest // Handled by `cs/useless-cast-to-self`
8787
}
8888

89-
/** Holds if this upcast is the argument of a call to `target`. */
90-
private predicate isArgument(Call c, Callable target) {
89+
pragma[nomagic]
90+
private predicate isArgument(Type t) {
9191
exists(Parameter p |
9292
this = p.getAnAssignedArgument() and
93-
p.getType() = this.getType() and
94-
c.getAnArgument() = this and
95-
target = c.getTarget()
93+
t = p.getType()
9694
)
9795
}
9896

97+
/** Holds if this upcast is the argument of a call to `target`. */
98+
private predicate isArgument(Call c, Callable target) {
99+
this.isArgument(this.getType()) and
100+
c.getAnArgument() = this and
101+
target = c.getTarget()
102+
}
103+
99104
/** Holds if this upcast may be used to disambiguate the target of an instance call. */
100105
pragma[nomagic]
101106
private predicate isDisambiguatingInstanceCall(InstanceCallable other, int args) {

csharp/ql/src/semmle/code/csharp/Conversion.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,11 +601,12 @@ private predicate convArrayTypeCovariance(ArrayType fromType, ArrayType toType)
601601
convArrayTypeCovarianceJoin(fromType, toType, toType.getDimension(), toType.getRank())
602602
}
603603

604-
pragma[noinline]
604+
pragma[nomagic]
605605
private predicate convArrayTypeCovarianceJoin(ArrayType fromType, ArrayType toType, int dim, int rnk) {
606606
convArrayElementType(fromType, toType.getElementType(), dim, rnk)
607607
}
608608

609+
pragma[nomagic]
609610
private predicate convArrayElementType(ArrayType at, ArrayElementType aet, int dim, int rnk) {
610611
convRefTypeNonNull(at.getElementType(), aet) and
611612
dim = at.getDimension() and

csharp/ql/src/semmle/code/csharp/Variable.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ class Parameter extends DotNet::Parameter, LocalScopeVariable, Attributable, Top
237237
* The assigned arguments to `x` are `1` and `4`, the assigned argument to
238238
* `y` is `5`, and the assigned arguments to `z` are `3` and `6`, respectively.
239239
*/
240+
pragma[nomagic]
240241
Expr getAnAssignedArgument() { result = getCallable().getACall().getArgumentForParameter(this) }
241242

242243
/** Holds if this parameter is potentially overwritten in the body of its callable. */

csharp/ql/src/semmle/code/csharp/commons/StructuralComparison.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ abstract class StructuralComparisonConfiguration extends string {
7777

7878
private predicate sameByValue(Expr x, Expr y) { sameByValueAux(x, y, y.getValue()) }
7979

80-
pragma[noinline]
80+
pragma[nomagic]
8181
private predicate sameByValueAux(Expr x, Expr y, string value) {
8282
candidateInternal(x, y) and
8383
value = x.getValue()
@@ -203,7 +203,7 @@ module Internal {
203203

204204
private predicate sameByValue(Expr x, Expr y) { sameByValueAux(x, y, y.getValue()) }
205205

206-
pragma[noinline]
206+
pragma[nomagic]
207207
private predicate sameByValueAux(Expr x, Expr y, string value) {
208208
candidateInternal(x, y) and
209209
value = x.getValue()

csharp/ql/src/semmle/code/csharp/controlflow/Guards.qll

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,12 @@ module AbstractValues {
261261

262262
private import AbstractValues
263263

264+
pragma[nomagic]
265+
private predicate typePattern(PatternMatch pm, TypePatternExpr tpe, Type t) {
266+
tpe = pm.getPattern() and
267+
t = pm.getExpr().getType()
268+
}
269+
264270
/**
265271
* An expression that evaluates to a value that can be dereferenced. That is,
266272
* an expression that may evaluate to `null`.
@@ -337,19 +343,23 @@ class DereferenceableExpr extends Expr {
337343
or
338344
result =
339345
any(PatternMatch pm |
340-
pm.getExpr() = this and
341-
if pm.getPattern() instanceof NullLiteral
342-
then
346+
this = pm.getExpr() and
347+
(
343348
// E.g. `x is null`
349+
pm.getPattern() instanceof NullLiteral and
344350
isNull = branch
345-
else (
351+
or
346352
// E.g. `x is string` or `x is ""`
347-
branch = true and isNull = false
353+
not pm.getPattern() instanceof NullLiteral and
354+
branch = true and
355+
isNull = false
348356
or
349-
// E.g. `x is string` where `x` has type `string`
350-
pm.getPattern().(TypePatternExpr).getCheckedType() = pm.getExpr().getType() and
351-
branch = false and
352-
isNull = true
357+
exists(TypePatternExpr tpe |
358+
// E.g. `x is string` where `x` has type `string`
359+
typePattern(result, tpe, tpe.getCheckedType()) and
360+
branch = false and
361+
isNull = true
362+
)
353363
)
354364
)
355365
or
@@ -1248,6 +1258,7 @@ module Internal {
12481258
)
12491259
}
12501260

1261+
pragma[nomagic]
12511262
private Expr getAnEqualityCheckVal(Expr e, AbstractValue v, AbstractValue vExpr) {
12521263
result = getAnEqualityCheck(e, v, vExpr.getAnExpr())
12531264
}

csharp/ql/src/semmle/code/csharp/controlflow/internal/Completion.qll

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,16 @@ private class TriedControlFlowElement extends ControlFlowElement {
388388
}
389389
}
390390

391-
pragma[noinline]
391+
pragma[nomagic]
392+
private ValueOrRefType getACastExprBaseType(CastExpr ce) {
393+
result = ce.getType().(ValueOrRefType).getABaseType()
394+
or
395+
result = getACastExprBaseType(ce).getABaseType()
396+
}
397+
398+
pragma[nomagic]
392399
private predicate invalidCastCandidate(CastExpr ce) {
393-
ce.getType() = ce.getExpr().getType().(ValueOrRefType).getASubType+()
400+
ce.getExpr().getType() = getACastExprBaseType(ce)
394401
}
395402

396403
private predicate assertion(Assertion a, int i, AssertMethod am, Expr e) {

csharp/ql/src/semmle/code/csharp/dataflow/SSA.qll

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,11 +1820,12 @@ module Ssa {
18201820
BasicBlock bb, int i, LocalScopeSourceVariable v, ImplicitEntryDefinition def,
18211821
ControlFlow::Nodes::ElementNode c, boolean additionalCalls
18221822
) {
1823-
exists(Callable reader |
1823+
exists(Callable reader, SourceVariable sv |
18241824
implicitReadCandidate(bb, i, c, v) and
18251825
readsCapturedVariable(c, v, reader, additionalCalls) and
1826-
def.getCallable() = reader and
1827-
def.getSourceVariable().getAssignable() = v.getAssignable()
1826+
sv = def.getSourceVariable() and
1827+
reader = sv.getEnclosingCallable() and
1828+
v.getAssignable() = sv.getAssignable()
18281829
)
18291830
}
18301831

csharp/ql/src/semmle/code/csharp/frameworks/NHibernate.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ module NHibernate {
7979
this.getCallable()
8080
.getDeclaringType()
8181
.getDeclaringNamespace()
82-
.getParent*()
82+
.getParentNamespace*()
8383
.hasQualifiedName("", "NHibernate")
8484
}
8585
}

0 commit comments

Comments
 (0)