Lecture 9: InterproceduralAnalysis
17-355/17-655/17-819: Program AnalysisRohan Padhye and Jonathan Aldrich
March 4, 2021
* Course materials developed with Claire Le Goues
1(c) 2021 J. Aldrich, C. Le Goues, R. Padhye
Approach #1: Analyze functions independentlyβ’ Pretend function f() cannot see the source of function g()β’ Simulates separate compilation and dynamic linking (e.g. C, Java)β’ Create CFG for each function body and run intraprocedural analysisβ’ Q: What should be is π! andπ" π₯ β π(π¦) and π" return π₯ for zero
analysis?
7(c) 2021 J. Aldrich, C. Le Goues, R. Padhye
Approach #2: User-defined Annotations
9(c) 2021 J. Aldrich, C. Le Goues, R. Padhye
@NonZero -> @NonZero
Approach #2: User-defined Annotations
10(c) 2021 J. Aldrich, C. Le Goues, R. Padhye
@NonZero -> @NonZero @NonZero -> @NonZero
Error!
Approach #2: User-defined Annotations
11(c) 2021 J. Aldrich, C. Le Goues, R. Padhye
@NonZero -> @NonZero @Any -> @NonZero
Error!
Approach #3: Interprocedural CFG
12(c) 2021 J. Aldrich, C. Le Goues, R. Padhye
3:returnπ¦
1:fun πππ’πππ(π₯)
2:π¦ β 2 β π₯
4:fun ππππ()
7:β¦
5:π§ β 0
local
6:π€ β πππ’πππ(π§)returnw
call
π! return π₯ "#$ π = π§ β π π§ π§ β πΊππππππ } βͺ {πππ‘ β π(π₯)}
π! π₯ β π π¦ %&'(% π = π \ ( π₯ βͺ πΊππππππ )π! π₯ β π π¦ '(%% π = {ππππππ π β π π¦ }
Approach #3: Interprocedural CFG
13(c) 2021 J. Aldrich, C. Le Goues, R. Padhye
Exercise: What would be the result of zero analysis for this program on line 7 and at the end?
Approach #3: Interprocedural CFG
14(c) 2021 J. Aldrich, C. Le Goues, R. Padhye
3:returnπ¦
1:fun πππ’πππ(π₯)
2:π¦ β 2 β π₯
4:fun ππππ()
7:z:=10/w
5:π§ β 5
local
6:π€ β πππ’πππ(π§)returnw
call
8:π§ β 0
9:π€ β πππ’πππ(π§)call
10:β¦localreturnw
Problems with Interprocedural CFGβ’ Merges ( joins) information across call sites to same functionβ’ Loses precisionβ’ Models infeasible paths (call from one site and return to another)β’ Can we βrememberβ where to return data-flow values?
15(c) 2021 J. Aldrich, C. Le Goues, R. Padhye
Context-Sensitive Analysis Example
17(c) 2021 J. Aldrich, C. Le Goues, R. Padhye
Key idea: Separate analyses for functions called in different βcontextsβ.
(βcontextβ = some statically definable condition)
Context-Sensitive Analysis Example
18(c) 2021 J. Aldrich, C. Le Goues, R. Padhye
Context πππ ππππ
Line 6 {x->N} {x->N, y->N}
Line 9 {x->Z} {x->Z, y->Z}
Context-Sensitive Analysis Example
19(c) 2021 J. Aldrich, C. Le Goues, R. Padhye
Context πππ ππππ
<main, T> T {w->Z, Z->Z}
<double, N> {x->N} {x->N, y->N}
<double, Z> {x->Z} {x->Z, y->Z}
Top Related