Skip to content

Commit d114388

Browse files
committed
Swift: Implement 'isAbnormalExitType' and accept test changes.
1 parent 12d1811 commit d114388

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

swift/ql/lib/codeql/swift/controlflow/internal/ControlFlowGraphImplSpecific.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ predicate successorTypeIsSimple(SuccessorType t) {
4545
}
4646

4747
/** Holds if `t` is an abnormal exit type out of a CFG scope. */
48-
predicate isAbnormalExitType(SuccessorType t) { none() } // TODO
48+
predicate isAbnormalExitType(SuccessorType t) {
49+
t instanceof CFG::SuccessorTypes::ExceptionSuccessor
50+
}
4951

5052
class Location = S::Location;
5153

swift/ql/test/library-tests/controlflow/graph/Cfg.expected

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ cfg.swift:
5353

5454
# 17| exit mightThrow(x:)
5555

56+
# 17| exit mightThrow(x:) (abnormal)
57+
#-----| -> exit mightThrow(x:)
58+
5659
# 17| exit mightThrow(x:) (normal)
5760
#-----| -> exit mightThrow(x:)
5861

@@ -85,7 +88,7 @@ cfg.swift:
8588
#-----| -> ... .>=(_:_:) ...
8689

8790
# 19| throw ...
88-
#-----| exception -> exit mightThrow(x:) (normal)
91+
#-----| exception -> exit mightThrow(x:) (abnormal)
8992

9093
# 19| MyError.Type
9194
#-----| -> (Error) ...
@@ -119,7 +122,7 @@ cfg.swift:
119122
#-----| -> ... .<=(_:_:) ...
120123

121124
# 22| throw ...
122-
#-----| exception -> exit mightThrow(x:) (normal)
125+
#-----| exception -> exit mightThrow(x:) (abnormal)
123126

124127
# 22| MyError.Type
125128
#-----| -> .+(_:_:)
@@ -1724,6 +1727,9 @@ cfg.swift:
17241727

17251728
# 181| exit m1(x:)
17261729

1730+
# 181| exit m1(x:) (abnormal)
1731+
#-----| -> exit m1(x:)
1732+
17271733
# 181| exit m1(x:) (normal)
17281734
#-----| -> exit m1(x:)
17291735

@@ -1790,24 +1796,24 @@ cfg.swift:
17901796
#-----| true -> { ... }
17911797

17921798
# 185| ... .&&(_:_:) ...
1793-
#-----| exception -> exit m1(x:) (normal)
1799+
#-----| exception -> exit m1(x:) (abnormal)
17941800
#-----| false -> [false] ... .&&(_:_:) ...
17951801
#-----| true -> { ... }
17961802

17971803
# 185| [false] ... .&&(_:_:) ...
1798-
#-----| exception -> exit m1(x:) (normal)
1804+
#-----| exception -> exit m1(x:) (abnormal)
17991805
#-----| false -> [false] ... .&&(_:_:) ...
18001806

18011807
# 185| ... .&&(_:_:) ...
1802-
#-----| exception -> exit m1(x:) (normal)
1808+
#-----| exception -> exit m1(x:) (abnormal)
18031809
#-----| true -> print(_:separator:terminator:)
18041810
#-----| false -> print(_:separator:terminator:)
18051811

18061812
# 185| StmtCondition
18071813
#-----| -> .<=(_:_:)
18081814

18091815
# 185| [false] ... .&&(_:_:) ...
1810-
#-----| exception -> exit m1(x:) (normal)
1816+
#-----| exception -> exit m1(x:) (abnormal)
18111817
#-----| false -> print(_:separator:terminator:)
18121818

18131819
# 185| .<=(_:_:)
@@ -2285,6 +2291,9 @@ cfg.swift:
22852291

22862292
# 237| exit disjunct(b1:b2:)
22872293

2294+
# 237| exit disjunct(b1:b2:) (abnormal)
2295+
#-----| -> exit disjunct(b1:b2:)
2296+
22882297
# 237| exit disjunct(b1:b2:) (normal)
22892298
#-----| -> exit disjunct(b1:b2:)
22902299

@@ -2311,12 +2320,12 @@ cfg.swift:
23112320
#-----| false -> { ... }
23122321

23132322
# 238| ... .||(_:_:) ...
2314-
#-----| exception -> exit disjunct(b1:b2:) (normal)
2323+
#-----| exception -> exit disjunct(b1:b2:) (abnormal)
23152324
#-----| false -> [false] (...)
23162325
#-----| true -> [true] (...)
23172326

23182327
# 238| [true] ... .||(_:_:) ...
2319-
#-----| exception -> exit disjunct(b1:b2:) (normal)
2328+
#-----| exception -> exit disjunct(b1:b2:) (abnormal)
23202329
#-----| true -> [true] (...)
23212330

23222331
# 238| b2
@@ -5050,6 +5059,9 @@ cfg.swift:
50505059

50515060
# 383| exit doWithoutCatch(x:)
50525061

5062+
# 383| exit doWithoutCatch(x:) (abnormal)
5063+
#-----| -> exit doWithoutCatch(x:)
5064+
50535065
# 383| exit doWithoutCatch(x:) (normal)
50545066
#-----| -> exit doWithoutCatch(x:)
50555067

@@ -5066,7 +5078,7 @@ cfg.swift:
50665078
#-----| -> 0
50675079

50685080
# 385| call to mightThrow(x:)
5069-
#-----| exception -> exit doWithoutCatch(x:) (normal)
5081+
#-----| exception -> exit doWithoutCatch(x:) (abnormal)
50705082
#-----| -> try ...
50715083

50725084
# 385| 0
@@ -5103,7 +5115,7 @@ cfg.swift:
51035115
#-----| -> 0
51045116

51055117
# 387| call to mightThrow(x:)
5106-
#-----| exception -> exit doWithoutCatch(x:) (normal)
5118+
#-----| exception -> exit doWithoutCatch(x:) (abnormal)
51075119
#-----| -> try! ...
51085120

51095121
# 387| 0

0 commit comments

Comments
 (0)