Skip to content

Commit 0513828

Browse files
authored
Merge pull request #922 from hvitved/csharp/cfg/remove-exception-edges
C#: Remove some impossible CFG exception edges
2 parents e10ea73 + 8cb8c96 commit 0513828

21 files changed

+3052
-2950
lines changed

csharp/ql/src/semmle/code/csharp/controlflow/internal/Completion.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ private class TriedControlFlowElement extends ControlFlowElement {
207207
or
208208
this = any(MemberAccess ma |
209209
not ma.isConditional() and
210-
ma.hasQualifier() and
210+
ma.getQualifier() = any(Expr e | not e instanceof TypeAccess) and
211211
result instanceof SystemNullReferenceExceptionClass
212212
)
213213
or
@@ -236,7 +236,7 @@ private class TriedControlFlowElement extends ControlFlowElement {
236236
)
237237
or
238238
this = any(DivExpr de |
239-
not de.getDenominator().getValue().toInt() != 0 and
239+
not de.getDenominator().getValue().toFloat() != 0 and
240240
result instanceof SystemDivideByZeroExceptionClass
241241
)
242242
or

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

Lines changed: 78 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -503,80 +503,81 @@
503503
| cflow.cs:244:17:244:37 | [finally: exception(NullReferenceException)] ...; | cflow.cs:244:17:244:36 | [finally: exception(NullReferenceException)] call to method WriteLine | 3 |
504504
| cflow.cs:244:17:244:37 | [finally: exception(OutOfMemoryException)] ...; | cflow.cs:244:17:244:36 | [finally: exception(OutOfMemoryException)] call to method WriteLine | 3 |
505505
| cflow.cs:244:17:244:37 | [finally: return] ...; | cflow.cs:244:17:244:36 | [finally: return] call to method WriteLine | 3 |
506-
| cflow.cs:248:10:248:12 | enter For | cflow.cs:251:9:252:33 | for (...;...;...) ... | 7 |
507-
| cflow.cs:248:10:248:12 | exit For | cflow.cs:248:10:248:12 | exit For | 1 |
508-
| cflow.cs:251:16:251:16 | access to local variable x | cflow.cs:251:16:251:21 | ... < ... | 3 |
509-
| cflow.cs:252:13:252:33 | ...; | cflow.cs:251:24:251:26 | ++... | 5 |
510-
| cflow.cs:254:9:259:9 | for (...;...;...) ... | cflow.cs:254:9:259:9 | for (...;...;...) ... | 1 |
511-
| cflow.cs:254:18:254:18 | access to local variable x | cflow.cs:254:18:254:20 | ...++ | 2 |
512-
| cflow.cs:255:9:259:9 | {...} | cflow.cs:257:17:257:22 | ... > ... | 8 |
513-
| cflow.cs:258:17:258:22 | break; | cflow.cs:261:9:267:9 | for (...;...;...) ... | 2 |
514-
| cflow.cs:262:9:267:9 | {...} | cflow.cs:265:17:265:22 | ... > ... | 11 |
515-
| cflow.cs:266:17:266:22 | break; | cflow.cs:269:9:273:9 | for (...;...;...) ... | 2 |
516-
| cflow.cs:269:16:269:16 | access to local variable x | cflow.cs:269:16:269:21 | ... < ... | 3 |
517-
| cflow.cs:270:9:273:9 | {...} | cflow.cs:272:13:272:15 | ...++ | 7 |
518-
| cflow.cs:275:9:278:9 | for (...;...;...) ... | cflow.cs:275:25:275:29 | Int32 j = ... | 7 |
519-
| cflow.cs:275:32:275:32 | access to local variable i | cflow.cs:275:32:275:41 | ... < ... | 5 |
520-
| cflow.cs:276:9:278:9 | {...} | cflow.cs:275:49:275:51 | ...++ | 10 |
521-
| cflow.cs:281:10:281:16 | enter Lambdas | cflow.cs:281:10:281:16 | exit Lambdas | 11 |
522-
| cflow.cs:283:28:283:37 | enter (...) => ... | cflow.cs:283:28:283:37 | exit (...) => ... | 5 |
523-
| cflow.cs:284:28:284:61 | enter delegate(...) { ... } | cflow.cs:284:28:284:61 | exit delegate(...) { ... } | 7 |
524-
| cflow.cs:287:10:287:18 | enter LogicalOr | cflow.cs:287:10:287:18 | exit LogicalOr | 19 |
525-
| cflow.cs:295:10:295:17 | enter Booleans | cflow.cs:297:17:297:32 | ... > ... | 10 |
526-
| cflow.cs:295:10:295:17 | exit Booleans | cflow.cs:295:10:295:17 | exit Booleans | 1 |
527-
| cflow.cs:297:13:297:56 | Boolean b = ... | cflow.cs:299:15:299:31 | ... == ... | 9 |
528-
| cflow.cs:297:37:297:56 | !... | cflow.cs:297:39:297:55 | ... == ... | 6 |
529-
| cflow.cs:299:35:299:39 | false | cflow.cs:300:17:300:33 | ... == ... | 9 |
530-
| cflow.cs:299:43:299:46 | true | cflow.cs:299:43:299:46 | true | 1 |
531-
| cflow.cs:300:13:300:48 | ... = ... | cflow.cs:300:13:300:48 | ... = ... | 1 |
532-
| cflow.cs:300:37:300:41 | false | cflow.cs:300:37:300:41 | false | 1 |
533-
| cflow.cs:300:45:300:48 | true | cflow.cs:300:45:300:48 | true | 1 |
534-
| cflow.cs:302:9:307:9 | if (...) ... | cflow.cs:302:15:302:31 | ... == ... | 8 |
535-
| cflow.cs:302:37:302:62 | !... | cflow.cs:302:40:302:56 | ... == ... | 8 |
536-
| cflow.cs:302:61:302:61 | access to local variable b | cflow.cs:302:61:302:61 | access to local variable b | 1 |
537-
| cflow.cs:303:9:307:9 | {...} | cflow.cs:305:17:305:38 | throw ...; | 4 |
538-
| cflow.cs:310:10:310:11 | enter Do | cflow.cs:312:9:323:36 | do ... while (...); | 3 |
539-
| cflow.cs:310:10:310:11 | exit Do | cflow.cs:310:10:310:11 | exit Do | 1 |
540-
| cflow.cs:313:9:323:9 | {...} | cflow.cs:315:17:315:32 | ... > ... | 15 |
541-
| cflow.cs:316:13:318:13 | {...} | cflow.cs:317:17:317:25 | continue; | 2 |
542-
| cflow.cs:319:13:322:13 | if (...) ... | cflow.cs:319:17:319:32 | ... < ... | 6 |
543-
| cflow.cs:320:13:322:13 | {...} | cflow.cs:321:17:321:22 | break; | 2 |
544-
| cflow.cs:323:18:323:22 | this access | cflow.cs:323:18:323:34 | ... < ... | 5 |
545-
| cflow.cs:326:10:326:16 | enter Foreach | cflow.cs:328:27:328:64 | call to method Repeat | 5 |
546-
| cflow.cs:326:10:326:16 | exit Foreach | cflow.cs:326:10:326:16 | exit Foreach | 1 |
547-
| cflow.cs:328:9:339:9 | foreach (... ... in ...) ... | cflow.cs:328:9:339:9 | foreach (... ... in ...) ... | 1 |
548-
| cflow.cs:328:22:328:22 | String x | cflow.cs:331:17:331:32 | ... > ... | 16 |
549-
| cflow.cs:332:13:334:13 | {...} | cflow.cs:333:17:333:25 | continue; | 2 |
550-
| cflow.cs:335:13:338:13 | if (...) ... | cflow.cs:335:17:335:32 | ... < ... | 6 |
551-
| cflow.cs:336:13:338:13 | {...} | cflow.cs:337:17:337:22 | break; | 2 |
552-
| cflow.cs:342:10:342:13 | enter Goto | cflow.cs:343:5:361:5 | {...} | 2 |
553-
| cflow.cs:342:10:342:13 | exit Goto | cflow.cs:342:10:342:13 | exit Goto | 1 |
554-
| cflow.cs:344:9:344:13 | Label: | cflow.cs:344:23:344:39 | ... == ... | 9 |
555-
| cflow.cs:344:43:344:45 | {...} | cflow.cs:344:43:344:45 | {...} | 1 |
556-
| cflow.cs:346:9:346:41 | if (...) ... | cflow.cs:346:13:346:28 | ... > ... | 6 |
557-
| cflow.cs:346:31:346:41 | goto ...; | cflow.cs:346:31:346:41 | goto ...; | 1 |
558-
| cflow.cs:348:9:360:9 | switch (...) {...} | cflow.cs:350:18:350:18 | 0 | 8 |
559-
| cflow.cs:351:17:351:29 | goto default; | cflow.cs:351:17:351:29 | goto default; | 1 |
560-
| cflow.cs:352:13:352:19 | case ...: | cflow.cs:352:18:352:18 | 1 | 2 |
561-
| cflow.cs:353:17:353:37 | ...; | cflow.cs:354:17:354:22 | break; | 4 |
562-
| cflow.cs:355:13:355:19 | case ...: | cflow.cs:355:18:355:18 | 2 | 2 |
563-
| cflow.cs:356:17:356:27 | goto ...; | cflow.cs:356:17:356:27 | goto ...; | 1 |
564-
| cflow.cs:357:13:357:20 | default: | cflow.cs:359:17:359:22 | break; | 5 |
565-
| cflow.cs:363:49:363:53 | enter Yield | cflow.cs:366:18:366:22 | Int32 i = ... | 8 |
566-
| cflow.cs:366:25:366:25 | access to local variable i | cflow.cs:366:25:366:30 | ... < ... | 3 |
567-
| cflow.cs:367:9:369:9 | {...} | cflow.cs:366:33:366:35 | ...++ | 5 |
568-
| cflow.cs:370:9:378:9 | try {...} ... | cflow.cs:363:49:363:53 | exit Yield | 8 |
569-
| cflow.cs:384:5:384:18 | enter ControlFlowSub | cflow.cs:384:5:384:18 | exit ControlFlowSub | 4 |
570-
| cflow.cs:386:5:386:18 | enter ControlFlowSub | cflow.cs:386:5:386:18 | exit ControlFlowSub | 4 |
571-
| cflow.cs:388:5:388:18 | enter ControlFlowSub | cflow.cs:388:5:388:18 | exit ControlFlowSub | 6 |
572-
| cflow.cs:393:10:393:10 | enter M | cflow.cs:397:31:397:35 | "Try" | 6 |
573-
| cflow.cs:393:10:393:10 | exit M | cflow.cs:393:10:393:10 | exit M | 1 |
574-
| cflow.cs:397:13:397:36 | call to method WriteLine | cflow.cs:397:13:397:36 | call to method WriteLine | 1 |
575-
| cflow.cs:400:9:403:9 | [finally: exception(Exception)] {...} | cflow.cs:401:13:401:44 | [finally: exception(Exception)] throw ...; | 4 |
576-
| cflow.cs:400:9:403:9 | [finally: exception(OutOfMemoryException)] {...} | cflow.cs:401:13:401:44 | [finally: exception(OutOfMemoryException)] throw ...; | 4 |
577-
| cflow.cs:400:9:403:9 | {...} | cflow.cs:401:13:401:44 | throw ...; | 4 |
578-
| cflow.cs:410:12:410:12 | enter M | cflow.cs:410:12:410:12 | exit M | 5 |
579-
| cflow.cs:415:5:415:25 | enter NegationInConstructor | cflow.cs:415:5:415:25 | exit NegationInConstructor | 3 |
580-
| cflow.cs:417:10:417:10 | enter M | cflow.cs:419:46:419:50 | ... > ... | 9 |
581-
| cflow.cs:419:56:419:56 | access to parameter s | cflow.cs:419:56:419:64 | ... != ... | 3 |
582-
| cflow.cs:419:70:419:71 | "" | cflow.cs:417:10:417:10 | exit M | 3 |
506+
| cflow.cs:247:9:254:9 | try {...} ... | cflow.cs:249:17:249:40 | Double temp = ... | 9 |
507+
| cflow.cs:257:10:257:12 | enter For | cflow.cs:260:9:261:33 | for (...;...;...) ... | 7 |
508+
| cflow.cs:257:10:257:12 | exit For | cflow.cs:257:10:257:12 | exit For | 1 |
509+
| cflow.cs:260:16:260:16 | access to local variable x | cflow.cs:260:16:260:21 | ... < ... | 3 |
510+
| cflow.cs:261:13:261:33 | ...; | cflow.cs:260:24:260:26 | ++... | 5 |
511+
| cflow.cs:263:9:268:9 | for (...;...;...) ... | cflow.cs:263:9:268:9 | for (...;...;...) ... | 1 |
512+
| cflow.cs:263:18:263:18 | access to local variable x | cflow.cs:263:18:263:20 | ...++ | 2 |
513+
| cflow.cs:264:9:268:9 | {...} | cflow.cs:266:17:266:22 | ... > ... | 8 |
514+
| cflow.cs:267:17:267:22 | break; | cflow.cs:270:9:276:9 | for (...;...;...) ... | 2 |
515+
| cflow.cs:271:9:276:9 | {...} | cflow.cs:274:17:274:22 | ... > ... | 11 |
516+
| cflow.cs:275:17:275:22 | break; | cflow.cs:278:9:282:9 | for (...;...;...) ... | 2 |
517+
| cflow.cs:278:16:278:16 | access to local variable x | cflow.cs:278:16:278:21 | ... < ... | 3 |
518+
| cflow.cs:279:9:282:9 | {...} | cflow.cs:281:13:281:15 | ...++ | 7 |
519+
| cflow.cs:284:9:287:9 | for (...;...;...) ... | cflow.cs:284:25:284:29 | Int32 j = ... | 7 |
520+
| cflow.cs:284:32:284:32 | access to local variable i | cflow.cs:284:32:284:41 | ... < ... | 5 |
521+
| cflow.cs:285:9:287:9 | {...} | cflow.cs:284:49:284:51 | ...++ | 10 |
522+
| cflow.cs:290:10:290:16 | enter Lambdas | cflow.cs:290:10:290:16 | exit Lambdas | 11 |
523+
| cflow.cs:292:28:292:37 | enter (...) => ... | cflow.cs:292:28:292:37 | exit (...) => ... | 5 |
524+
| cflow.cs:293:28:293:61 | enter delegate(...) { ... } | cflow.cs:293:28:293:61 | exit delegate(...) { ... } | 7 |
525+
| cflow.cs:296:10:296:18 | enter LogicalOr | cflow.cs:296:10:296:18 | exit LogicalOr | 19 |
526+
| cflow.cs:304:10:304:17 | enter Booleans | cflow.cs:306:17:306:32 | ... > ... | 10 |
527+
| cflow.cs:304:10:304:17 | exit Booleans | cflow.cs:304:10:304:17 | exit Booleans | 1 |
528+
| cflow.cs:306:13:306:56 | Boolean b = ... | cflow.cs:308:15:308:31 | ... == ... | 9 |
529+
| cflow.cs:306:37:306:56 | !... | cflow.cs:306:39:306:55 | ... == ... | 6 |
530+
| cflow.cs:308:35:308:39 | false | cflow.cs:309:17:309:33 | ... == ... | 9 |
531+
| cflow.cs:308:43:308:46 | true | cflow.cs:308:43:308:46 | true | 1 |
532+
| cflow.cs:309:13:309:48 | ... = ... | cflow.cs:309:13:309:48 | ... = ... | 1 |
533+
| cflow.cs:309:37:309:41 | false | cflow.cs:309:37:309:41 | false | 1 |
534+
| cflow.cs:309:45:309:48 | true | cflow.cs:309:45:309:48 | true | 1 |
535+
| cflow.cs:311:9:316:9 | if (...) ... | cflow.cs:311:15:311:31 | ... == ... | 8 |
536+
| cflow.cs:311:37:311:62 | !... | cflow.cs:311:40:311:56 | ... == ... | 8 |
537+
| cflow.cs:311:61:311:61 | access to local variable b | cflow.cs:311:61:311:61 | access to local variable b | 1 |
538+
| cflow.cs:312:9:316:9 | {...} | cflow.cs:314:17:314:38 | throw ...; | 4 |
539+
| cflow.cs:319:10:319:11 | enter Do | cflow.cs:321:9:332:36 | do ... while (...); | 3 |
540+
| cflow.cs:319:10:319:11 | exit Do | cflow.cs:319:10:319:11 | exit Do | 1 |
541+
| cflow.cs:322:9:332:9 | {...} | cflow.cs:324:17:324:32 | ... > ... | 15 |
542+
| cflow.cs:325:13:327:13 | {...} | cflow.cs:326:17:326:25 | continue; | 2 |
543+
| cflow.cs:328:13:331:13 | if (...) ... | cflow.cs:328:17:328:32 | ... < ... | 6 |
544+
| cflow.cs:329:13:331:13 | {...} | cflow.cs:330:17:330:22 | break; | 2 |
545+
| cflow.cs:332:18:332:22 | this access | cflow.cs:332:18:332:34 | ... < ... | 5 |
546+
| cflow.cs:335:10:335:16 | enter Foreach | cflow.cs:337:27:337:64 | call to method Repeat | 5 |
547+
| cflow.cs:335:10:335:16 | exit Foreach | cflow.cs:335:10:335:16 | exit Foreach | 1 |
548+
| cflow.cs:337:9:348:9 | foreach (... ... in ...) ... | cflow.cs:337:9:348:9 | foreach (... ... in ...) ... | 1 |
549+
| cflow.cs:337:22:337:22 | String x | cflow.cs:340:17:340:32 | ... > ... | 16 |
550+
| cflow.cs:341:13:343:13 | {...} | cflow.cs:342:17:342:25 | continue; | 2 |
551+
| cflow.cs:344:13:347:13 | if (...) ... | cflow.cs:344:17:344:32 | ... < ... | 6 |
552+
| cflow.cs:345:13:347:13 | {...} | cflow.cs:346:17:346:22 | break; | 2 |
553+
| cflow.cs:351:10:351:13 | enter Goto | cflow.cs:352:5:370:5 | {...} | 2 |
554+
| cflow.cs:351:10:351:13 | exit Goto | cflow.cs:351:10:351:13 | exit Goto | 1 |
555+
| cflow.cs:353:9:353:13 | Label: | cflow.cs:353:23:353:39 | ... == ... | 9 |
556+
| cflow.cs:353:43:353:45 | {...} | cflow.cs:353:43:353:45 | {...} | 1 |
557+
| cflow.cs:355:9:355:41 | if (...) ... | cflow.cs:355:13:355:28 | ... > ... | 6 |
558+
| cflow.cs:355:31:355:41 | goto ...; | cflow.cs:355:31:355:41 | goto ...; | 1 |
559+
| cflow.cs:357:9:369:9 | switch (...) {...} | cflow.cs:359:18:359:18 | 0 | 8 |
560+
| cflow.cs:360:17:360:29 | goto default; | cflow.cs:360:17:360:29 | goto default; | 1 |
561+
| cflow.cs:361:13:361:19 | case ...: | cflow.cs:361:18:361:18 | 1 | 2 |
562+
| cflow.cs:362:17:362:37 | ...; | cflow.cs:363:17:363:22 | break; | 4 |
563+
| cflow.cs:364:13:364:19 | case ...: | cflow.cs:364:18:364:18 | 2 | 2 |
564+
| cflow.cs:365:17:365:27 | goto ...; | cflow.cs:365:17:365:27 | goto ...; | 1 |
565+
| cflow.cs:366:13:366:20 | default: | cflow.cs:368:17:368:22 | break; | 5 |
566+
| cflow.cs:372:49:372:53 | enter Yield | cflow.cs:375:18:375:22 | Int32 i = ... | 8 |
567+
| cflow.cs:375:25:375:25 | access to local variable i | cflow.cs:375:25:375:30 | ... < ... | 3 |
568+
| cflow.cs:376:9:378:9 | {...} | cflow.cs:375:33:375:35 | ...++ | 5 |
569+
| cflow.cs:379:9:387:9 | try {...} ... | cflow.cs:372:49:372:53 | exit Yield | 8 |
570+
| cflow.cs:393:5:393:18 | enter ControlFlowSub | cflow.cs:393:5:393:18 | exit ControlFlowSub | 4 |
571+
| cflow.cs:395:5:395:18 | enter ControlFlowSub | cflow.cs:395:5:395:18 | exit ControlFlowSub | 4 |
572+
| cflow.cs:397:5:397:18 | enter ControlFlowSub | cflow.cs:397:5:397:18 | exit ControlFlowSub | 6 |
573+
| cflow.cs:402:10:402:10 | enter M | cflow.cs:406:31:406:35 | "Try" | 6 |
574+
| cflow.cs:402:10:402:10 | exit M | cflow.cs:402:10:402:10 | exit M | 1 |
575+
| cflow.cs:406:13:406:36 | call to method WriteLine | cflow.cs:406:13:406:36 | call to method WriteLine | 1 |
576+
| cflow.cs:409:9:412:9 | [finally: exception(Exception)] {...} | cflow.cs:410:13:410:44 | [finally: exception(Exception)] throw ...; | 4 |
577+
| cflow.cs:409:9:412:9 | [finally: exception(OutOfMemoryException)] {...} | cflow.cs:410:13:410:44 | [finally: exception(OutOfMemoryException)] throw ...; | 4 |
578+
| cflow.cs:409:9:412:9 | {...} | cflow.cs:410:13:410:44 | throw ...; | 4 |
579+
| cflow.cs:419:12:419:12 | enter M | cflow.cs:419:12:419:12 | exit M | 5 |
580+
| cflow.cs:424:5:424:25 | enter NegationInConstructor | cflow.cs:424:5:424:25 | exit NegationInConstructor | 3 |
581+
| cflow.cs:426:10:426:10 | enter M | cflow.cs:428:46:428:50 | ... > ... | 9 |
582+
| cflow.cs:428:56:428:56 | access to parameter s | cflow.cs:428:56:428:64 | ... != ... | 3 |
583+
| cflow.cs:428:70:428:71 | "" | cflow.cs:426:10:426:10 | exit M | 3 |

0 commit comments

Comments
 (0)