Skip to content

Commit 723699a

Browse files
committed
C#: Add SSA test for overlapping captured variable definitions
1 parent 4125241 commit 723699a

12 files changed

+50
-0
lines changed

csharp/ql/test/library-tests/dataflow/ssa/Capture.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,22 @@ void M1()
236236
M3();
237237
System.Console.WriteLine(i);
238238
}
239+
240+
void M2()
241+
{
242+
int i = 0;
243+
void CaptureWrite()
244+
{
245+
i = 1;
246+
}
247+
248+
void CaptureAndRef(ref int i)
249+
{
250+
CaptureWrite();
251+
i = 2;
252+
}
253+
254+
CaptureAndRef(ref i); // explicit definition only (no call definition)
255+
System.Console.WriteLine(i);
256+
}
239257
}

csharp/ql/test/library-tests/dataflow/ssa/DefAdjacentRead.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
| Capture.cs:203:28:203:30 | eh2 | Capture.cs:203:28:203:45 | MyEventHandler eh2 = ... | Capture.cs:204:27:204:29 | access to local variable eh2 |
3131
| Capture.cs:210:24:210:24 | p | Capture.cs:210:24:210:59 | Process p = ... | Capture.cs:213:17:213:17 | access to local variable p |
3232
| Capture.cs:212:30:212:35 | exited | Capture.cs:212:30:212:71 | EventHandler exited = ... | Capture.cs:213:29:213:34 | access to local variable exited |
33+
| Capture.cs:242:13:242:13 | i | Capture.cs:242:13:242:17 | Int32 i = ... | Capture.cs:254:27:254:27 | access to local variable i |
34+
| Capture.cs:242:13:242:13 | i | Capture.cs:254:27:254:27 | access to local variable i | Capture.cs:255:34:255:34 | access to local variable i |
3335
| Consistency.cs:7:25:7:25 | b | Consistency.cs:7:25:7:25 | b | Consistency.cs:11:17:11:17 | access to parameter b |
3436
| Consistency.cs:15:17:15:17 | i | Consistency.cs:15:17:15:21 | Int32 i = ... | Consistency.cs:16:17:16:17 | access to local variable i |
3537
| Consistency.cs:25:29:25:29 | c | Consistency.cs:25:29:25:29 | Consistency c | Consistency.cs:26:13:26:13 | access to local variable c |

csharp/ql/test/library-tests/dataflow/ssa/IsLiveOutRefParameterDefinition.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
| Capture.cs:81:28:81:28 | i | Capture.cs:81:34:81:36 | SSA def(i) |
2+
| Capture.cs:248:36:248:36 | i | Capture.cs:251:13:251:17 | SSA def(i) |
23
| Consistency.cs:30:30:30:30 | c | Consistency.cs:32:9:32:29 | SSA def(c) |
34
| DefUse.cs:114:42:114:42 | i | DefUse.cs:114:47:114:52 | SSA def(i) |
45
| DefUse.cs:116:42:116:42 | i | DefUse.cs:116:47:116:51 | SSA def(i) |

csharp/ql/test/library-tests/dataflow/ssa/SsaCapturedVariableDef.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@
3737
| out | Capture.cs:139:13:139:13 | d | Capture.cs:142:13:142:17 | SSA def(d) | Capture.cs:144:9:144:12 | SSA call def(d) | Capture.cs:144:9:144:12 | call to local function M4 | false |
3838
| out | Capture.cs:168:13:168:13 | h | Capture.cs:174:17:174:21 | SSA def(h) | Capture.cs:176:13:176:16 | SSA call def(h) | Capture.cs:176:13:176:16 | call to local function M9 | false |
3939
| out | Capture.cs:229:13:229:13 | i | Capture.cs:235:21:235:25 | SSA def(i) | Capture.cs:236:9:236:12 | SSA call def(i) | Capture.cs:236:9:236:12 | call to local function M3 | false |
40+
| out | Capture.cs:242:13:242:13 | i | Capture.cs:245:13:245:17 | SSA def(i) | Capture.cs:254:9:254:28 | SSA call def(i) | Capture.cs:254:9:254:28 | call to local function CaptureAndRef | true |
4041
| out | DefUse.cs:167:23:167:23 | i | DefUse.cs:173:13:173:17 | SSA def(i) | DefUse.cs:181:9:181:11 | SSA call def(i) | DefUse.cs:181:9:181:11 | delegate call | false |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| Capture.cs:255:34:255:34 | access to local variable i | Read is associated with multiple SSA definitions |

csharp/ql/test/library-tests/dataflow/ssa/SsaDef.expected

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@
8282
| Capture.cs:229:13:229:13 | i | Capture.cs:232:9:232:13 | SSA def(i) |
8383
| Capture.cs:229:13:229:13 | i | Capture.cs:235:21:235:25 | SSA def(i) |
8484
| Capture.cs:229:13:229:13 | i | Capture.cs:236:9:236:12 | SSA call def(i) |
85+
| Capture.cs:242:13:242:13 | i | Capture.cs:242:13:242:17 | SSA def(i) |
86+
| Capture.cs:242:13:242:13 | i | Capture.cs:245:13:245:17 | SSA def(i) |
87+
| Capture.cs:242:13:242:13 | i | Capture.cs:254:9:254:28 | SSA call def(i) |
88+
| Capture.cs:242:13:242:13 | i | Capture.cs:254:27:254:27 | SSA def(i) |
89+
| Capture.cs:248:36:248:36 | i | Capture.cs:251:13:251:17 | SSA def(i) |
8590
| Consistency.cs:7:25:7:25 | b | Consistency.cs:7:25:7:25 | SSA param(b) |
8691
| Consistency.cs:15:17:15:17 | i | Consistency.cs:15:17:15:21 | SSA def(i) |
8792
| Consistency.cs:15:17:15:17 | i | Consistency.cs:15:17:15:21 | [finally: exception(Exception)] SSA def(i) |

csharp/ql/test/library-tests/dataflow/ssa/SsaDefElement.expected

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@
8282
| Capture.cs:232:9:232:13 | SSA def(i) | Capture.cs:232:9:232:13 | ... = ... |
8383
| Capture.cs:235:21:235:25 | SSA def(i) | Capture.cs:235:21:235:25 | ... = ... |
8484
| Capture.cs:236:9:236:12 | SSA call def(i) | Capture.cs:236:9:236:12 | call to local function M3 |
85+
| Capture.cs:242:13:242:17 | SSA def(i) | Capture.cs:242:13:242:17 | Int32 i = ... |
86+
| Capture.cs:245:13:245:17 | SSA def(i) | Capture.cs:245:13:245:17 | ... = ... |
87+
| Capture.cs:251:13:251:17 | SSA def(i) | Capture.cs:251:13:251:17 | ... = ... |
88+
| Capture.cs:254:9:254:28 | SSA call def(i) | Capture.cs:254:9:254:28 | call to local function CaptureAndRef |
89+
| Capture.cs:254:27:254:27 | SSA def(i) | Capture.cs:254:9:254:28 | call to local function CaptureAndRef |
8590
| Consistency.cs:7:25:7:25 | SSA param(b) | Consistency.cs:7:25:7:25 | b |
8691
| Consistency.cs:15:17:15:21 | SSA def(i) | Consistency.cs:15:17:15:21 | Int32 i = ... |
8792
| Consistency.cs:15:17:15:21 | [finally: exception(Exception)] SSA def(i) | Consistency.cs:15:17:15:21 | Int32 i = ... |

csharp/ql/test/library-tests/dataflow/ssa/SsaDefLastRead.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
| Capture.cs:212:30:212:35 | exited | Capture.cs:212:30:212:71 | SSA def(exited) | Capture.cs:213:29:213:34 | access to local variable exited |
5959
| Capture.cs:229:13:229:13 | i | Capture.cs:231:9:231:49 | SSA capture def(i) | Capture.cs:231:47:231:47 | access to local variable i |
6060
| Capture.cs:229:13:229:13 | i | Capture.cs:236:9:236:12 | SSA call def(i) | Capture.cs:237:34:237:34 | access to local variable i |
61+
| Capture.cs:242:13:242:13 | i | Capture.cs:242:13:242:17 | SSA def(i) | Capture.cs:254:27:254:27 | access to local variable i |
62+
| Capture.cs:242:13:242:13 | i | Capture.cs:254:9:254:28 | SSA call def(i) | Capture.cs:255:34:255:34 | access to local variable i |
63+
| Capture.cs:242:13:242:13 | i | Capture.cs:254:27:254:27 | SSA def(i) | Capture.cs:255:34:255:34 | access to local variable i |
6164
| Consistency.cs:7:25:7:25 | b | Consistency.cs:7:25:7:25 | SSA param(b) | Consistency.cs:11:17:11:17 | access to parameter b |
6265
| Consistency.cs:15:17:15:17 | i | Consistency.cs:15:17:15:21 | SSA def(i) | Consistency.cs:16:17:16:17 | access to local variable i |
6366
| Consistency.cs:15:17:15:17 | i | Consistency.cs:15:17:15:21 | [finally: exception(Exception)] SSA def(i) | Consistency.cs:16:17:16:17 | access to local variable i |

csharp/ql/test/library-tests/dataflow/ssa/SsaExplicitDef.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@
5454
| Capture.cs:212:30:212:35 | exited | Capture.cs:212:30:212:71 | SSA def(exited) | Capture.cs:212:30:212:71 | EventHandler exited = ... |
5555
| Capture.cs:229:13:229:13 | i | Capture.cs:232:9:232:13 | SSA def(i) | Capture.cs:232:9:232:13 | ... = ... |
5656
| Capture.cs:229:13:229:13 | i | Capture.cs:235:21:235:25 | SSA def(i) | Capture.cs:235:21:235:25 | ... = ... |
57+
| Capture.cs:242:13:242:13 | i | Capture.cs:242:13:242:17 | SSA def(i) | Capture.cs:242:13:242:17 | Int32 i = ... |
58+
| Capture.cs:242:13:242:13 | i | Capture.cs:245:13:245:17 | SSA def(i) | Capture.cs:245:13:245:17 | ... = ... |
59+
| Capture.cs:242:13:242:13 | i | Capture.cs:254:27:254:27 | SSA def(i) | Capture.cs:254:27:254:27 | access to local variable i |
60+
| Capture.cs:248:36:248:36 | i | Capture.cs:251:13:251:17 | SSA def(i) | Capture.cs:251:13:251:17 | ... = ... |
5761
| Consistency.cs:7:25:7:25 | b | Consistency.cs:7:25:7:25 | SSA param(b) | Consistency.cs:7:25:7:25 | b |
5862
| Consistency.cs:15:17:15:17 | i | Consistency.cs:15:17:15:21 | SSA def(i) | Consistency.cs:15:17:15:21 | Int32 i = ... |
5963
| Consistency.cs:15:17:15:17 | i | Consistency.cs:15:17:15:21 | [finally: exception(Exception)] SSA def(i) | Consistency.cs:15:17:15:21 | Int32 i = ... |

csharp/ql/test/library-tests/dataflow/ssa/SsaImplicitCall.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
| Capture.cs:139:13:139:13 | d | Capture.cs:144:9:144:12 | SSA call def(d) | Capture.cs:142:13:142:17 | ... = ... |
1010
| Capture.cs:168:13:168:13 | h | Capture.cs:176:13:176:16 | SSA call def(h) | Capture.cs:174:17:174:21 | ... = ... |
1111
| Capture.cs:229:13:229:13 | i | Capture.cs:236:9:236:12 | SSA call def(i) | Capture.cs:235:21:235:25 | ... = ... |
12+
| Capture.cs:242:13:242:13 | i | Capture.cs:254:9:254:28 | SSA call def(i) | Capture.cs:245:13:245:17 | ... = ... |
1213
| DefUse.cs:167:23:167:23 | i | DefUse.cs:181:9:181:11 | SSA call def(i) | DefUse.cs:173:13:173:17 | ... = ... |
1314
| DefUse.cs:184:9:184:14 | this.Field5 | DefUse.cs:191:9:191:11 | SSA call def(this.Field5) | DefUse.cs:188:13:188:22 | ... = ... |
1415
| Example.cs:8:9:8:18 | this.Field | Example.cs:13:13:13:23 | SSA call def(this.Field) | Example.cs:8:9:8:22 | ... = ... |

0 commit comments

Comments
 (0)