Skip to content

Commit 997d9e8

Browse files
committed
Swift: Include 'self' parameter declaration in the CFG.
1 parent 09427af commit 997d9e8

File tree

2 files changed

+128
-14
lines changed

2 files changed

+128
-14
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,9 @@ module Decls {
993993
AbstractFunctionDecl getAst() { result = ast }
994994

995995
final override ControlFlowElement getChildElement(int i) {
996+
i = -1 and
997+
result.asAstNode() = ast.getSelfParam()
998+
or
996999
result.asAstNode() = ast.getParam(i)
9971000
or
9981001
result.asAstNode() = ast.getBody() and

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

Lines changed: 125 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ cfg.swift:
949949
#-----| -> ... .+(_:_:) ...
950950

951951
# 98| deinit
952-
#-----| -> { ... }
952+
#-----| -> self
953953

954954
# 98| enter deinit
955955
#-----| -> deinit
@@ -959,6 +959,9 @@ cfg.swift:
959959
# 98| exit deinit (normal)
960960
#-----| -> exit deinit
961961

962+
# 98| self
963+
#-----| -> { ... }
964+
962965
# 98| { ... }
963966
#-----| -> exit deinit (normal)
964967

@@ -971,6 +974,12 @@ cfg.swift:
971974
#-----| -> exit get
972975

973976
# 99| get
977+
#-----| -> self
978+
979+
# 99| self
980+
981+
# 100| self
982+
#-----| -> n
974983

975984
# 100| enter init
976985
#-----| -> init
@@ -981,7 +990,7 @@ cfg.swift:
981990
#-----| -> exit init
982991

983992
# 100| init
984-
#-----| -> n
993+
#-----| -> self
985994

986995
# 100| n
987996
#-----| -> self
@@ -1012,6 +1021,9 @@ cfg.swift:
10121021
# 104| getMyInt()
10131022
#-----| -> self
10141023

1024+
# 104| self
1025+
#-----| -> self
1026+
10151027
# 105| return ...
10161028
#-----| return -> exit getMyInt() (normal)
10171029

@@ -4678,7 +4690,7 @@ cfg.swift:
46784690
#-----| -> ... .+=(_:_:) ...
46794691

46804692
# 352| deinit
4681-
#-----| -> { ... }
4693+
#-----| -> self
46824694

46834695
# 352| enter deinit
46844696
#-----| -> deinit
@@ -4688,6 +4700,9 @@ cfg.swift:
46884700
# 352| exit deinit (normal)
46894701
#-----| -> exit deinit
46904702

4703+
# 352| self
4704+
#-----| -> { ... }
4705+
46914706
# 352| { ... }
46924707
#-----| -> exit deinit (normal)
46934708

@@ -4700,6 +4715,12 @@ cfg.swift:
47004715
#-----| -> exit get
47014716

47024717
# 353| get
4718+
#-----| -> self
4719+
4720+
# 353| self
4721+
4722+
# 354| self
4723+
#-----| -> arg
47034724

47044725
# 354| enter init
47054726
#-----| -> init
@@ -4710,7 +4731,7 @@ cfg.swift:
47104731
#-----| -> exit init
47114732

47124733
# 354| init
4713-
#-----| -> arg
4734+
#-----| -> self
47144735

47154736
# 354| arg
47164737
#-----| -> self
@@ -4741,6 +4762,9 @@ cfg.swift:
47414762
# 358| getOptional()
47424763
#-----| -> self
47434764

4765+
# 358| self
4766+
#-----| -> self
4767+
47444768
# 359| return ...
47454769
#-----| return -> exit getOptional() (normal)
47464770

@@ -4965,7 +4989,7 @@ cfg.swift:
49654989
#-----| -> #...
49664990

49674991
# 377| deinit
4968-
#-----| -> { ... }
4992+
#-----| -> self
49694993

49704994
# 377| enter deinit
49714995
#-----| -> deinit
@@ -4975,6 +4999,9 @@ cfg.swift:
49754999
# 377| exit deinit (normal)
49765000
#-----| -> exit deinit
49775001

5002+
# 377| self
5003+
#-----| -> { ... }
5004+
49785005
# 377| { ... }
49795006
#-----| -> exit deinit (normal)
49805007

@@ -4987,6 +5014,12 @@ cfg.swift:
49875014
#-----| -> exit init
49885015

49895016
# 377| init
5017+
#-----| -> self
5018+
5019+
# 377| self
5020+
5021+
# 378| self
5022+
#-----| -> init
49905023

49915024
# 378| enter init
49925025
#-----| -> init
@@ -4997,7 +5030,7 @@ cfg.swift:
49975030
#-----| -> exit init
49985031

49995032
# 378| init
5000-
#-----| -> init
5033+
#-----| -> self
50015034

50025035
# 379| super
50035036
#-----| -> call to ...
@@ -5118,6 +5151,7 @@ cfg.swift:
51185151
#-----| -> return ...
51195152

51205153
# 394| (unnamed function decl)
5154+
#-----| -> self
51215155

51225156
# 394| enter (unnamed function decl)
51235157
#-----| -> (unnamed function decl)
@@ -5144,15 +5178,26 @@ cfg.swift:
51445178
#-----| -> exit set
51455179

51465180
# 394| get
5181+
#-----| -> self
51475182

5148-
# 394| set
5183+
# 394| self
5184+
5185+
# 394| self
51495186
#-----| -> value
51505187

5188+
# 394| self
5189+
5190+
# 394| set
5191+
#-----| -> self
5192+
51515193
# 394| value
51525194

51535195
# 394| yield ...
51545196
#-----| -> exit (unnamed function decl) (normal)
51555197

5198+
# 395| self
5199+
#-----| -> self
5200+
51565201
# 395| enter init
51575202
#-----| -> init
51585203

@@ -5179,6 +5224,9 @@ cfg.swift:
51795224
# 397| return
51805225
#-----| return -> exit init (normal)
51815226

5227+
# 399| self
5228+
#-----| -> self
5229+
51825230
# 399| deinit
51835231
#-----| -> self
51845232

@@ -5258,7 +5306,7 @@ cfg.swift:
52585306
#-----| -> MyLocalStruct
52595307

52605308
# 409| deinit
5261-
#-----| -> { ... }
5309+
#-----| -> self
52625310

52635311
# 409| enter deinit
52645312
#-----| -> deinit
@@ -5268,10 +5316,14 @@ cfg.swift:
52685316
# 409| exit deinit (normal)
52695317
#-----| -> exit deinit
52705318

5319+
# 409| self
5320+
#-----| -> { ... }
5321+
52715322
# 409| { ... }
52725323
#-----| -> exit deinit (normal)
52735324

52745325
# 410| (unnamed function decl)
5326+
#-----| -> self
52755327

52765328
# 410| enter (unnamed function decl)
52775329
#-----| -> (unnamed function decl)
@@ -5298,15 +5350,26 @@ cfg.swift:
52985350
#-----| -> exit set
52995351

53005352
# 410| get
5353+
#-----| -> self
53015354

5302-
# 410| set
5355+
# 410| self
5356+
5357+
# 410| self
53035358
#-----| -> value
53045359

5360+
# 410| self
5361+
5362+
# 410| set
5363+
#-----| -> self
5364+
53055365
# 410| value
53065366

53075367
# 410| yield ...
53085368
#-----| -> exit (unnamed function decl) (normal)
53095369

5370+
# 411| self
5371+
#-----| -> self
5372+
53105373
# 411| enter init
53115374
#-----| -> init
53125375

@@ -5337,6 +5400,7 @@ cfg.swift:
53375400
#-----| -> MyLocalEnum
53385401

53395402
# 417| (unnamed function decl)
5403+
#-----| -> self
53405404

53415405
# 417| enter (unnamed function decl)
53425406
#-----| -> (unnamed function decl)
@@ -5363,15 +5427,26 @@ cfg.swift:
53635427
#-----| -> exit set
53645428

53655429
# 417| get
5430+
#-----| -> self
53665431

5367-
# 417| set
5432+
# 417| self
5433+
5434+
# 417| self
53685435
#-----| -> value
53695436

5437+
# 417| self
5438+
5439+
# 417| set
5440+
#-----| -> self
5441+
53705442
# 417| value
53715443

53725444
# 417| yield ...
53735445
#-----| -> exit (unnamed function decl) (normal)
53745446

5447+
# 418| self
5448+
#-----| -> self
5449+
53755450
# 418| enter init
53765451
#-----| -> init
53775452

@@ -5420,6 +5495,7 @@ cfg.swift:
54205495
#-----| -> return ...
54215496

54225497
# 446| (unnamed function decl)
5498+
#-----| -> self
54235499

54245500
# 446| enter (unnamed function decl)
54255501
#-----| -> (unnamed function decl)
@@ -5446,16 +5522,25 @@ cfg.swift:
54465522
#-----| -> exit set
54475523

54485524
# 446| get
5525+
#-----| -> self
54495526

5450-
# 446| set
5527+
# 446| self
5528+
5529+
# 446| self
54515530
#-----| -> value
54525531

5532+
# 446| self
5533+
5534+
# 446| set
5535+
#-----| -> self
5536+
54535537
# 446| value
54545538

54555539
# 446| yield ...
54565540
#-----| -> exit (unnamed function decl) (normal)
54575541

54585542
# 450| (unnamed function decl)
5543+
#-----| -> self
54595544

54605545
# 450| enter (unnamed function decl)
54615546
#-----| -> (unnamed function decl)
@@ -5482,16 +5567,25 @@ cfg.swift:
54825567
#-----| -> exit set
54835568

54845569
# 450| get
5570+
#-----| -> self
54855571

5486-
# 450| set
5572+
# 450| self
5573+
5574+
# 450| self
54875575
#-----| -> value
54885576

5577+
# 450| self
5578+
5579+
# 450| set
5580+
#-----| -> self
5581+
54895582
# 450| value
54905583

54915584
# 450| yield ...
54925585
#-----| -> exit (unnamed function decl) (normal)
54935586

54945587
# 451| (unnamed function decl)
5588+
#-----| -> self
54955589

54965590
# 451| enter (unnamed function decl)
54975591
#-----| -> (unnamed function decl)
@@ -5518,16 +5612,25 @@ cfg.swift:
55185612
#-----| -> exit set
55195613

55205614
# 451| get
5615+
#-----| -> self
55215616

5522-
# 451| set
5617+
# 451| self
5618+
5619+
# 451| self
55235620
#-----| -> value
55245621

5622+
# 451| self
5623+
5624+
# 451| set
5625+
#-----| -> self
5626+
55255627
# 451| value
55265628

55275629
# 451| yield ...
55285630
#-----| -> exit (unnamed function decl) (normal)
55295631

55305632
# 452| (unnamed function decl)
5633+
#-----| -> self
55315634

55325635
# 452| enter (unnamed function decl)
55335636
#-----| -> (unnamed function decl)
@@ -5554,10 +5657,18 @@ cfg.swift:
55545657
#-----| -> exit set
55555658

55565659
# 452| get
5660+
#-----| -> self
55575661

5558-
# 452| set
5662+
# 452| self
5663+
5664+
# 452| self
55595665
#-----| -> value
55605666

5667+
# 452| self
5668+
5669+
# 452| set
5670+
#-----| -> self
5671+
55615672
# 452| value
55625673

55635674
# 452| yield ...

0 commit comments

Comments
 (0)