Skip to content

Commit 917a156

Browse files
committed
Java: Fix CFG for rule statements.
1 parent 922a4e8 commit 917a156

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

java/ql/lib/semmle/code/java/ControlFlowGraph.qll

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,13 @@ private module ControlFlowGraphImpl {
871871
)
872872
or
873873
// the last node in a case rule is the last node in the right-hand side
874-
last(n.(SwitchCase).getRuleStatement(), last, completion)
874+
// if the rhs is a statement we wrap the completion as a break
875+
exists(Completion caseCompletion |
876+
last(n.(SwitchCase).getRuleStatement(), last, caseCompletion) and
877+
if caseCompletion instanceof NormalOrBooleanCompletion
878+
then completion = anonymousBreakCompletion()
879+
else completion = caseCompletion
880+
)
875881
or
876882
// ...and if the rhs is an expression we wrap the completion as a yield
877883
exists(Completion caseCompletion |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
| Test.java:5:7:5:17 | case ... | Test.java:3:20:3:20 | s | Test.java:5:12:5:14 | "c" | true | true | Test.java:5:7:5:17 | case ... |
22
| Test.java:6:7:6:17 | case ... | Test.java:3:20:3:20 | s | Test.java:6:12:6:14 | "d" | true | true | Test.java:6:7:6:17 | case ... |
3+
| Test.java:11:7:11:17 | case ... | Test.java:9:13:9:13 | s | Test.java:11:12:11:14 | "c" | true | false | Test.java:13:7:13:16 | default |
4+
| Test.java:11:7:11:17 | case ... | Test.java:9:13:9:13 | s | Test.java:11:12:11:14 | "c" | true | true | Test.java:11:7:11:17 | case ... |
5+
| Test.java:12:7:12:17 | case ... | Test.java:9:13:9:13 | s | Test.java:12:12:12:14 | "d" | true | false | Test.java:13:7:13:16 | default |
6+
| Test.java:12:7:12:17 | case ... | Test.java:9:13:9:13 | s | Test.java:12:12:12:14 | "d" | true | true | Test.java:12:7:12:17 | case ... |

0 commit comments

Comments
 (0)