Skip to content

Commit 9dbcb7c

Browse files
committed
C#: Improve various join orders
1 parent 931e695 commit 9dbcb7c

File tree

4 files changed

+34
-15
lines changed

4 files changed

+34
-15
lines changed

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/controlflow/Guards.qll

Lines changed: 19 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

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

0 commit comments

Comments
 (0)