Skip to content

Commit dc0b044

Browse files
authored
Merge pull request github#7185 from hvitved/csharp/ssa/consistency-queries
C#: Enable SSA consistency queries
2 parents 609d601 + 1d1780b commit dc0b044

File tree

12 files changed

+273
-155
lines changed

12 files changed

+273
-155
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import csharp
2+
import semmle.code.csharp.dataflow.internal.SsaImplCommon::Consistency
3+
4+
class MyRelevantDefinition extends RelevantDefinition, Ssa::Definition {
5+
override predicate hasLocationInfo(
6+
string filepath, int startline, int startcolumn, int endline, int endcolumn
7+
) {
8+
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
9+
}
10+
}

csharp/ql/lib/semmle/code/csharp/ExprOrStmtParent.qll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ private module Cached {
140140
}
141141

142142
private Expr getAChildExpr(ExprOrStmtParent parent) {
143-
result = parent.getAChildExpr() or
143+
result = parent.getAChildExpr() and
144+
not result = parent.(DeclarationWithGetSetAccessors).getExpressionBody()
145+
or
144146
result = parent.(AssignOperation).getExpandedAssignment()
145147
}
146148

@@ -159,7 +161,7 @@ private module Cached {
159161

160162
private predicate parent(ControlFlowElement child, ExprOrStmtParent parent) {
161163
child = getAChild(parent) and
162-
not child instanceof Callable
164+
not child = any(Callable c).getBody()
163165
}
164166

165167
/** Holds if the enclosing body of `cfe` is `body`. */

csharp/ql/lib/semmle/code/csharp/dataflow/internal/SsaImpl.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ private module SourceVariableImpl {
171171
def.getTarget() = lv and
172172
lv.isRef() and
173173
lv = v.getAssignable() and
174-
bb.getNode(i) = def.getAControlFlowNode()
174+
bb.getNode(i) = def.getAControlFlowNode() and
175+
not def.getAssignment() instanceof LocalVariableDeclAndInitExpr
175176
)
176177
}
177178

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,12 +1303,12 @@
13031303
| cflow.cs:234:13:236:13 | {...} | cflow.cs:235:17:235:22 | break; | 2 |
13041304
| cflow.cs:240:10:240:13 | enter Goto | cflow.cs:241:5:259:5 | {...} | 2 |
13051305
| cflow.cs:240:10:240:13 | exit Goto (normal) | cflow.cs:240:10:240:13 | exit Goto | 2 |
1306-
| cflow.cs:242:9:242:13 | Label: | cflow.cs:242:23:242:39 | ... == ... | 7 |
1307-
| cflow.cs:242:20:242:40 | [false] !... | cflow.cs:242:20:242:40 | [false] !... | 1 |
1308-
| cflow.cs:242:20:242:40 | [true] !... | cflow.cs:242:20:242:40 | [true] !... | 1 |
1309-
| cflow.cs:242:21:242:40 | [false] !... | cflow.cs:242:21:242:40 | [false] !... | 1 |
1310-
| cflow.cs:242:21:242:40 | [true] !... | cflow.cs:242:21:242:40 | [true] !... | 1 |
1311-
| cflow.cs:242:43:242:45 | {...} | cflow.cs:242:43:242:45 | {...} | 1 |
1306+
| cflow.cs:242:5:242:9 | Label: | cflow.cs:242:19:242:35 | ... == ... | 7 |
1307+
| cflow.cs:242:16:242:36 | [false] !... | cflow.cs:242:16:242:36 | [false] !... | 1 |
1308+
| cflow.cs:242:16:242:36 | [true] !... | cflow.cs:242:16:242:36 | [true] !... | 1 |
1309+
| cflow.cs:242:17:242:36 | [false] !... | cflow.cs:242:17:242:36 | [false] !... | 1 |
1310+
| cflow.cs:242:17:242:36 | [true] !... | cflow.cs:242:17:242:36 | [true] !... | 1 |
1311+
| cflow.cs:242:39:242:41 | {...} | cflow.cs:242:39:242:41 | {...} | 1 |
13121312
| cflow.cs:244:9:244:41 | if (...) ... | cflow.cs:244:13:244:28 | ... > ... | 6 |
13131313
| cflow.cs:244:31:244:41 | goto ...; | cflow.cs:244:31:244:41 | goto ...; | 1 |
13141314
| cflow.cs:246:9:258:9 | switch (...) {...} | cflow.cs:248:18:248:18 | 0 | 8 |
@@ -1332,3 +1332,5 @@
13321332
| cflow.cs:300:44:300:51 | [true] !... | cflow.cs:300:44:300:51 | [true] !... | 1 |
13331333
| cflow.cs:300:44:300:64 | ... && ... | cflow.cs:298:10:298:10 | exit M | 5 |
13341334
| cflow.cs:300:56:300:56 | access to parameter s | cflow.cs:300:56:300:64 | ... != ... | 3 |
1335+
| cflow.cs:306:60:310:5 | enter (...) => ... | cflow.cs:306:60:310:5 | exit (...) => ... | 9 |
1336+
| cflow.cs:306:60:310:5 | enter get__getter | cflow.cs:306:60:310:5 | exit get__getter | 4 |

csharp/ql/test/library-tests/controlflow/graph/Condition.expected

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2410,15 +2410,15 @@ conditionBlock
24102410
| cflow.cs:226:22:226:22 | String x | cflow.cs:233:13:236:13 | if (...) ... | false |
24112411
| cflow.cs:226:22:226:22 | String x | cflow.cs:234:13:236:13 | {...} | false |
24122412
| cflow.cs:233:13:236:13 | if (...) ... | cflow.cs:234:13:236:13 | {...} | true |
2413-
| cflow.cs:242:9:242:13 | Label: | cflow.cs:242:20:242:40 | [false] !... | false |
2414-
| cflow.cs:242:9:242:13 | Label: | cflow.cs:242:20:242:40 | [true] !... | true |
2415-
| cflow.cs:242:9:242:13 | Label: | cflow.cs:242:21:242:40 | [false] !... | true |
2416-
| cflow.cs:242:9:242:13 | Label: | cflow.cs:242:21:242:40 | [true] !... | false |
2417-
| cflow.cs:242:9:242:13 | Label: | cflow.cs:242:43:242:45 | {...} | true |
2418-
| cflow.cs:242:20:242:40 | [true] !... | cflow.cs:242:43:242:45 | {...} | true |
2419-
| cflow.cs:242:21:242:40 | [false] !... | cflow.cs:242:20:242:40 | [true] !... | false |
2420-
| cflow.cs:242:21:242:40 | [false] !... | cflow.cs:242:43:242:45 | {...} | false |
2421-
| cflow.cs:242:21:242:40 | [true] !... | cflow.cs:242:20:242:40 | [false] !... | true |
2413+
| cflow.cs:242:5:242:9 | Label: | cflow.cs:242:16:242:36 | [false] !... | false |
2414+
| cflow.cs:242:5:242:9 | Label: | cflow.cs:242:16:242:36 | [true] !... | true |
2415+
| cflow.cs:242:5:242:9 | Label: | cflow.cs:242:17:242:36 | [false] !... | true |
2416+
| cflow.cs:242:5:242:9 | Label: | cflow.cs:242:17:242:36 | [true] !... | false |
2417+
| cflow.cs:242:5:242:9 | Label: | cflow.cs:242:39:242:41 | {...} | true |
2418+
| cflow.cs:242:16:242:36 | [true] !... | cflow.cs:242:39:242:41 | {...} | true |
2419+
| cflow.cs:242:17:242:36 | [false] !... | cflow.cs:242:16:242:36 | [true] !... | false |
2420+
| cflow.cs:242:17:242:36 | [false] !... | cflow.cs:242:39:242:41 | {...} | false |
2421+
| cflow.cs:242:17:242:36 | [true] !... | cflow.cs:242:16:242:36 | [false] !... | true |
24222422
| cflow.cs:244:9:244:41 | if (...) ... | cflow.cs:240:10:240:13 | exit Goto (normal) | false |
24232423
| cflow.cs:244:9:244:41 | if (...) ... | cflow.cs:244:31:244:41 | goto ...; | true |
24242424
| cflow.cs:244:9:244:41 | if (...) ... | cflow.cs:246:9:258:9 | switch (...) {...} | false |
@@ -3007,12 +3007,12 @@ conditionFlow
30073007
| cflow.cs:229:17:229:32 | ... > ... | cflow.cs:233:13:236:13 | if (...) ... | false |
30083008
| cflow.cs:233:17:233:32 | ... < ... | cflow.cs:226:9:237:9 | foreach (... ... in ...) ... | false |
30093009
| cflow.cs:233:17:233:32 | ... < ... | cflow.cs:234:13:236:13 | {...} | true |
3010-
| cflow.cs:242:20:242:40 | [false] !... | cflow.cs:244:9:244:41 | if (...) ... | false |
3011-
| cflow.cs:242:20:242:40 | [true] !... | cflow.cs:242:43:242:45 | {...} | true |
3012-
| cflow.cs:242:21:242:40 | [false] !... | cflow.cs:242:20:242:40 | [true] !... | false |
3013-
| cflow.cs:242:21:242:40 | [true] !... | cflow.cs:242:20:242:40 | [false] !... | true |
3014-
| cflow.cs:242:23:242:39 | ... == ... | cflow.cs:242:21:242:40 | [false] !... | true |
3015-
| cflow.cs:242:23:242:39 | ... == ... | cflow.cs:242:21:242:40 | [true] !... | false |
3010+
| cflow.cs:242:16:242:36 | [false] !... | cflow.cs:244:9:244:41 | if (...) ... | false |
3011+
| cflow.cs:242:16:242:36 | [true] !... | cflow.cs:242:39:242:41 | {...} | true |
3012+
| cflow.cs:242:17:242:36 | [false] !... | cflow.cs:242:16:242:36 | [true] !... | false |
3013+
| cflow.cs:242:17:242:36 | [true] !... | cflow.cs:242:16:242:36 | [false] !... | true |
3014+
| cflow.cs:242:19:242:35 | ... == ... | cflow.cs:242:17:242:36 | [false] !... | true |
3015+
| cflow.cs:242:19:242:35 | ... == ... | cflow.cs:242:17:242:36 | [true] !... | false |
30163016
| cflow.cs:244:13:244:28 | ... > ... | cflow.cs:244:31:244:41 | goto ...; | true |
30173017
| cflow.cs:244:13:244:28 | ... > ... | cflow.cs:246:9:258:9 | switch (...) {...} | false |
30183018
| cflow.cs:264:25:264:30 | ... < ... | cflow.cs:265:9:267:9 | {...} | true |

0 commit comments

Comments
 (0)