Skip to content

Commit 3346b64

Browse files
committed
Rust: Add variables and data flow array tests
1 parent 06b1d8e commit 3346b64

File tree

6 files changed

+367
-186
lines changed

6 files changed

+367
-186
lines changed

rust/ql/test/library-tests/dataflow/local/DataFlowStep.expected

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,57 @@ localStep
344344
| main.rs:306:22:306:22 | [SSA] n | main.rs:306:34:306:34 | n |
345345
| main.rs:306:22:306:22 | n | main.rs:306:22:306:22 | [SSA] n |
346346
| main.rs:306:29:306:35 | sink(...) | main.rs:304:5:307:5 | match s2 { ... } |
347+
| main.rs:314:9:314:12 | [SSA] arr1 | main.rs:315:14:315:17 | arr1 |
348+
| main.rs:314:9:314:12 | arr1 | main.rs:314:9:314:12 | [SSA] arr1 |
349+
| main.rs:314:16:314:33 | [...] | main.rs:314:9:314:12 | arr1 |
350+
| main.rs:315:9:315:10 | [SSA] n1 | main.rs:316:10:316:11 | n1 |
351+
| main.rs:315:9:315:10 | n1 | main.rs:315:9:315:10 | [SSA] n1 |
352+
| main.rs:315:14:315:20 | arr1[2] | main.rs:315:9:315:10 | n1 |
353+
| main.rs:318:9:318:12 | [SSA] arr2 | main.rs:319:14:319:17 | arr2 |
354+
| main.rs:318:9:318:12 | arr2 | main.rs:318:9:318:12 | [SSA] arr2 |
355+
| main.rs:318:16:318:31 | [...] | main.rs:318:9:318:12 | arr2 |
356+
| main.rs:319:9:319:10 | [SSA] n2 | main.rs:320:10:320:11 | n2 |
357+
| main.rs:319:9:319:10 | n2 | main.rs:319:9:319:10 | [SSA] n2 |
358+
| main.rs:319:14:319:20 | arr2[4] | main.rs:319:9:319:10 | n2 |
359+
| main.rs:322:9:322:12 | [SSA] arr3 | main.rs:323:14:323:17 | arr3 |
360+
| main.rs:322:9:322:12 | arr3 | main.rs:322:9:322:12 | [SSA] arr3 |
361+
| main.rs:322:16:322:24 | [...] | main.rs:322:9:322:12 | arr3 |
362+
| main.rs:323:9:323:10 | [SSA] n3 | main.rs:324:10:324:11 | n3 |
363+
| main.rs:323:9:323:10 | n3 | main.rs:323:9:323:10 | [SSA] n3 |
364+
| main.rs:323:14:323:20 | arr3[2] | main.rs:323:9:323:10 | n3 |
365+
| main.rs:328:9:328:12 | [SSA] arr1 | main.rs:329:15:329:18 | arr1 |
366+
| main.rs:328:9:328:12 | arr1 | main.rs:328:9:328:12 | [SSA] arr1 |
367+
| main.rs:328:16:328:33 | [...] | main.rs:328:9:328:12 | arr1 |
368+
| main.rs:329:9:329:10 | [SSA] n1 | main.rs:330:14:330:15 | n1 |
369+
| main.rs:329:9:329:10 | n1 | main.rs:329:9:329:10 | [SSA] n1 |
370+
| main.rs:333:9:333:12 | [SSA] arr2 | main.rs:334:15:334:18 | arr2 |
371+
| main.rs:333:9:333:12 | arr2 | main.rs:333:9:333:12 | [SSA] arr2 |
372+
| main.rs:333:16:333:24 | [...] | main.rs:333:9:333:12 | arr2 |
373+
| main.rs:334:5:336:5 | for ... in ... { ... } | main.rs:327:21:337:1 | { ... } |
374+
| main.rs:334:9:334:10 | [SSA] n2 | main.rs:335:14:335:15 | n2 |
375+
| main.rs:334:9:334:10 | n2 | main.rs:334:9:334:10 | [SSA] n2 |
376+
| main.rs:340:9:340:12 | [SSA] arr1 | main.rs:341:11:341:14 | arr1 |
377+
| main.rs:340:9:340:12 | arr1 | main.rs:340:9:340:12 | [SSA] arr1 |
378+
| main.rs:340:16:340:33 | [...] | main.rs:340:9:340:12 | arr1 |
379+
| main.rs:341:5:347:5 | match arr1 { ... } | main.rs:339:26:348:1 | { ... } |
380+
| main.rs:341:11:341:14 | arr1 | main.rs:342:9:342:17 | SlicePat |
381+
| main.rs:342:10:342:10 | [SSA] a | main.rs:343:18:343:18 | a |
382+
| main.rs:342:10:342:10 | a | main.rs:342:10:342:10 | [SSA] a |
383+
| main.rs:342:13:342:13 | [SSA] b | main.rs:344:18:344:18 | b |
384+
| main.rs:342:13:342:13 | b | main.rs:342:13:342:13 | [SSA] b |
385+
| main.rs:342:16:342:16 | [SSA] c | main.rs:345:18:345:18 | c |
386+
| main.rs:342:16:342:16 | c | main.rs:342:16:342:16 | [SSA] c |
387+
| main.rs:342:22:346:9 | { ... } | main.rs:341:5:347:5 | match arr1 { ... } |
388+
| main.rs:351:9:351:19 | [SSA] mut_arr | main.rs:352:10:352:16 | mut_arr |
389+
| main.rs:351:9:351:19 | mut_arr | main.rs:351:9:351:19 | [SSA] mut_arr |
390+
| main.rs:351:23:351:31 | [...] | main.rs:351:9:351:19 | mut_arr |
391+
| main.rs:354:5:354:11 | [SSA] mut_arr | main.rs:355:13:355:19 | mut_arr |
392+
| main.rs:354:5:354:11 | mut_arr | main.rs:354:5:354:11 | [SSA] mut_arr |
393+
| main.rs:354:18:354:27 | source(...) | main.rs:354:5:354:14 | mut_arr[1] |
394+
| main.rs:355:9:355:9 | [SSA] d | main.rs:356:10:356:10 | d |
395+
| main.rs:355:9:355:9 | d | main.rs:355:9:355:9 | [SSA] d |
396+
| main.rs:355:13:355:19 | mut_arr | main.rs:357:10:357:16 | mut_arr |
397+
| main.rs:355:13:355:22 | mut_arr[1] | main.rs:355:9:355:9 | d |
347398
storeStep
348399
| main.rs:94:14:94:22 | source(...) | tuple.0 | main.rs:94:13:94:26 | TupleExpr |
349400
| main.rs:94:25:94:25 | 2 | tuple.1 | main.rs:94:13:94:26 | TupleExpr |
@@ -385,7 +436,7 @@ storeStep
385436
| main.rs:276:41:276:41 | 2 | D | main.rs:276:14:276:43 | ...::D {...} |
386437
| main.rs:294:18:294:27 | source(...) | C | main.rs:293:14:295:5 | C {...} |
387438
| main.rs:296:27:296:27 | 2 | D | main.rs:296:14:296:29 | D {...} |
388-
| main.rs:314:27:314:27 | 0 | Some | main.rs:314:22:314:28 | Some(...) |
439+
| main.rs:364:27:364:27 | 0 | Some | main.rs:364:22:364:28 | Some(...) |
389440
readStep
390441
| file://:0:0:0:0 | [summary param] self in lang:core::_::<crate::option::Option>::unwrap | Some | file://:0:0:0:0 | [summary] read: Argument[self].Variant[crate::option::Option::Some(0)] in lang:core::_::<crate::option::Option>::unwrap |
391442
| main.rs:33:9:33:15 | TupleStructPat | Some | main.rs:33:14:33:14 | _ |

rust/ql/test/library-tests/dataflow/local/main.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,56 @@ fn custom_record_enum_pattern_match_unqualified() {
307307
}
308308
}
309309

310+
// -----------------------------------------------------------------------------
311+
// Data flow through arrays
312+
313+
fn array_lookup() {
314+
let arr1 = [1, 2, source(94)];
315+
let n1 = arr1[2];
316+
sink(n1); // $ MISSING: hasValueFlow=94
317+
318+
let arr2 = [source(20); 10];
319+
let n2 = arr2[4];
320+
sink(n2); // $ MISSING: hasValueFlow=20
321+
322+
let arr3 = [1, 2, 3];
323+
let n3 = arr3[2];
324+
sink(n3);
325+
}
326+
327+
fn array_for_loop() {
328+
let arr1 = [1, 2, source(43)];
329+
for n1 in arr1 {
330+
sink(n1); // $ MISSING: hasValueFlow=43
331+
}
332+
333+
let arr2 = [1, 2, 3];
334+
for n2 in arr2 {
335+
sink(n2);
336+
}
337+
}
338+
339+
fn array_slice_pattern() {
340+
let arr1 = [1, 2, source(43)];
341+
match arr1 {
342+
[a, b, c] => {
343+
sink(a);
344+
sink(b);
345+
sink(c); // $ MISSING: hasValueFlow=43
346+
}
347+
}
348+
}
349+
350+
fn array_assignment() {
351+
let mut mut_arr = [1, 2, 3];
352+
sink(mut_arr[1]);
353+
354+
mut_arr[1] = source(55);
355+
let d = mut_arr[1];
356+
sink(d); // $ MISSING: hasValueFlow=55
357+
sink(mut_arr[0]);
358+
}
359+
310360
fn main() {
311361
direct();
312362
variable_usage();
@@ -334,4 +384,8 @@ fn main() {
334384
block_expression1();
335385
block_expression2(true);
336386
block_expression3(true);
387+
array_lookup();
388+
array_for_loop();
389+
array_slice_pattern();
390+
array_assignment();
337391
}

0 commit comments

Comments
 (0)