Skip to content

Commit c069c33

Browse files
committed
Fix tests
1 parent cb9a9db commit c069c33

File tree

18 files changed

+36
-16
lines changed

18 files changed

+36
-16
lines changed

csharp/extractor/Semmle.Extraction.CSharp/Entities/Parameter.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,10 @@ Symbol.ContainingSymbol is IMethodSymbol ms &&
164164
// In case this parameter belongs to an accessor of an indexer, we need
165165
// to get the default value from the corresponding parameter belonging
166166
// to the indexer itself
167-
var method = (IMethodSymbol)symbol.ContainingSymbol;
168-
if (method is not null)
167+
if (symbol.ContainingSymbol is IMethodSymbol method)
169168
{
170169
var i = method.Parameters.IndexOf(symbol);
171-
var indexer = (IPropertySymbol?)method.AssociatedSymbol;
172-
if (indexer is not null)
170+
if (method.AssociatedSymbol is IPropertySymbol indexer)
173171
defaultValue = GetParameterDefaultValue(indexer.Parameters[i]);
174172
}
175173
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ class Element extends DotNet::Element, @element {
2727
/** Gets a location of this element, including sources and assemblies. */
2828
override Location getALocation() { none() }
2929

30-
/** Holds if this element is from an assembly. */
31-
predicate fromLibrary() { this.getFile().fromLibrary() }
32-
3330
/** Gets the parent of this element, if any. */
3431
Element getParent() { result.getAChild() = this }
3532

csharp/ql/src/semmle/code/dotnet/Element.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ class Element extends @dotnet_element {
2828
/** Holds if this element is from source code. */
2929
predicate fromSource() { this.getFile().fromSource() }
3030

31+
/** Holds if this element is from an assembly. */
32+
predicate fromLibrary() { this.getFile().fromLibrary() }
33+
3134
/**
3235
* Gets the "language" of this program element, as defined by the extension of the filename.
3336
* For example, C# has language "cs", and Visual Basic has language "vb".

csharp/ql/test/library-tests/controlflow/graph/BasicBlock.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ import csharp
22
import Common
33

44
from SourceBasicBlock bb
5+
where not bb.getFirstNode().getElement().fromLibrary()
56
select bb.getFirstNode(), bb.getLastNode(), bb.length()
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
import csharp
22
import Common
33

4+
/** Holds if `node` is not from a library. */
5+
private predicate isSourceBased(SourceControlFlowNode node) { not node.getElement().fromLibrary() }
6+
47
query predicate dominance(SourceControlFlowNode dom, SourceControlFlowNode node) {
8+
isSourceBased(dom) and
59
dom.strictlyDominates(node) and
610
dom.getASuccessor() = node
711
}
812

913
query predicate postDominance(SourceControlFlowNode dom, SourceControlFlowNode node) {
14+
isSourceBased(dom) and
1015
dom.strictlyPostDominates(node) and
1116
dom.getAPredecessor() = node
1217
}
1318

14-
query predicate blockDominance(SourceBasicBlock dom, SourceBasicBlock bb) { dom.dominates(bb) }
19+
query predicate blockDominance(SourceBasicBlock dom, SourceBasicBlock bb) {
20+
isSourceBased(dom.getFirstNode()) and dom.dominates(bb)
21+
}
1522

1623
query predicate postBlockDominance(SourceBasicBlock dom, SourceBasicBlock bb) {
17-
dom.postDominates(bb)
24+
isSourceBased(dom.getFirstNode()) and dom.postDominates(bb)
1825
}

csharp/ql/test/library-tests/controlflow/graph/NodeGraph.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Common
44
query predicate edges(
55
SourceControlFlowNode node, SourceControlFlowNode successor, string attr, string val
66
) {
7+
not node.getElement().fromLibrary() and
78
exists(ControlFlow::SuccessorType t | successor = node.getASuccessorByType(t) |
89
attr = "semmle.label" and
910
val = t.toString()

csharp/ql/test/library-tests/controlflow/splits/SplittingStressTest.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import csharp
22

33
query predicate countSplits(ControlFlowElement cfe, int i) {
4+
not cfe.fromLibrary() and
45
i = strictcount(ControlFlow::Nodes::ElementNode n | n.getElement() = cfe)
56
}
67

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import csharp
22

33
from DefaultValueExpr l
4+
where l.fromSource()
45
select l, l.getValue()

csharp/ql/test/library-tests/csharp7/LocalTaintFlow.ql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@ import csharp
22
import semmle.code.csharp.dataflow.TaintTracking
33

44
from DataFlow::Node pred, DataFlow::Node succ
5-
where TaintTracking::localTaintStep(pred, succ)
5+
where
6+
TaintTracking::localTaintStep(pred, succ) and
7+
not pred.asExpr().fromLibrary()
68
select pred, succ
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import csharp
22

33
from DataFlow::Node pred, DataFlow::Node succ
4-
where DataFlow::localFlowStep(pred, succ)
4+
where not pred.asExpr().fromLibrary() and DataFlow::localFlowStep(pred, succ)
55
select pred, succ

0 commit comments

Comments
 (0)