100
A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang (Georgia Tech), Wonchan Lee, Hakjoo Oh, Kwangkeun Yi (Seoul National Univ.) Saturday, 8 June 13

A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

A few lessons that I learnt about interprocedural analyses

Hongseok Yang (Univ. of Oxford)

Mayur Naik, Ravi Mangal, Xin Zhang (Georgia Tech), Wonchan Lee, Hakjoo Oh, Kwangkeun Yi (Seoul National Univ.)

Saturday, 8 June 13

Page 2: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

A few lessons that I learnt about interprocedural analyses

Hongseok Yang (Univ. of Oxford)

Mayur Naik, Ravi Mangal, Xin Zhang (Georgia Tech), Wonchan Lee, Hakjoo Oh, Kwangkeun Yi (Seoul National Univ.)

Scalable static analyses for Java, which use cheap finite abstract domains.

Saturday, 8 June 13

Page 3: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

A few lessons that I learnt about interprocedural analyses

Hongseok Yang (Univ. of Oxford)

Mayur Naik, Ravi Mangal, Xin Zhang (Georgia Tech), Wonchan Lee, Hakjoo Oh, Kwangkeun Yi (Seoul National Univ.)

Static analyses for C based on infinite numerical abstract domains

Saturday, 8 June 13

Page 4: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

A few lessons that I learnt about interprocedural analyses

Hongseok Yang (Univ. of Oxford)

Mayur Naik, Ravi Mangal, Xin Zhang (Georgia Tech), Wonchan Lee, Hakjoo Oh, Kwangkeun Yi (Seoul National Univ.)

Saturday, 8 June 13

Page 5: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

Lesson 1

• Handling procedures well is really important in static analysis.

• Hajoo: About 50% false alarms of Sparse Sparrow on make and tar are due to procedures.

Saturday, 8 June 13

Page 6: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

Lesson 2

• Two popular approaches for analysing procedures are equivalent, even when analyses are not distributive.

Saturday, 8 June 13

Page 7: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

Lesson 2

• Two popular approaches for analysing procedures are equivalent, even when analyses are not distributive.

0: int x;1: void main() { 2: x = 1; inc();3: x = 1; foo();4: x = -x; 5: inc();6: }7:8: void foo() { inc(); }9: void inc() { x++; }

Callstring-based summary of inc[2]: x>0 [3,8]: x>0 [5]: x<=0

Input-output summary of incx>0 ↦ x>0 x<0 ↦ x<=0

Saturday, 8 June 13

Page 8: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

Lesson 3

• Often we can effectively guess program points where procedures should be analysed precisely.

Saturday, 8 June 13

Page 9: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

Outline

• Review of callstring and functional approaches.

• Equivalence between these approaches (Lesson 2).

• Partial context-sensitivity (Lesson 3).

Saturday, 8 June 13

Page 10: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

Outline

• Review of callstring and functional approaches.

• Equivalence between these approaches (Lesson 2).

• Partial context-sensitivity (Lesson 3).

with Naik, Mangal and Zhang

Saturday, 8 June 13

Page 11: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

Outline

• Review of callstring and functional approaches.

• Equivalence between these approaches (Lesson 2).

• Partial context-sensitivity (Lesson 3).

with Naik, Mangal and Zhang

with Lee, Oh and Yi

Saturday, 8 June 13

Page 12: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

Sign domain

• Abstract values:

• An abstract state is a map from variables to abstract values. E.g. [x:0+, y:-].

0

-0

- +

0+

Saturday, 8 June 13

Page 13: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

Context-insensitive analysis

• It treats function calls and returns as gotos, and do not match call and return.

• Ignores calling contexts.

• Most imprecise but popular approach for handling procedures.

Saturday, 8 June 13

Page 14: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc(); 7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {]14: x++;15: }

Context-insensitive analysis: Treat call & return as gotos, and do not match them.

Saturday, 8 June 13

Page 15: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc(); 7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {]14: x++;15: }

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: goto 14;5: }6: goto 14; 7: assert(x > 0);8: x = -x; 9: goto 14;10: assert(x >= 0);11: }12:13: void inc() {]14: x++; goto {5,7,10}15: }

Context-insensitive analysis: Treat call & return as gotos, and do not match them.

Saturday, 8 June 13

Page 16: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc(); 7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: goto 14;5: }6: goto 14; 7: assert(x > 0);8: x = -x; 9: goto 14;10: assert(x >= 0);11: }12:13: void inc() {14: x++; goto {5,7,10}15: }

Context-insensitive analysis: Treat call & return as gotos, and do not match them.

Saturday, 8 June 13

Page 17: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc(); 7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: goto 14;5: }6: goto 14; 7: assert(x > 0);8: x = -x; 9: goto 14;10: assert(x >= 0);11: }12:13: void inc() {14: x++; goto {5,7,10}15: }

Context-insensitive analysis: Treat call & return as gotos, and do not match them.

Saturday, 8 June 13

Page 18: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc(); 7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: goto 14;5: }6: goto 14; 7: assert(x > 0);8: x = -x; 9: goto 14;10: assert(x >= 0);11: }12:13: void inc() {14: x++; goto {5,7,10}15: }

Context-insensitive analysis: Treat call & return as gotos, and do not match them.

The analysis returns a false alarm at line 7.

Saturday, 8 June 13

Page 19: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

Context sensitivity

• Distinguish calling contexts and analyse each procedure separately for different contexts.

• The functional approach does so based on input abstract states.

• The callstring approach uses call strings (i.e., sequences of call sites) instead.

Saturday, 8 June 13

Page 20: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc(); 7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

Functional approach: Separate analysis for each input abstract state.

Saturday, 8 June 13

Page 21: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc(); 7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:+] [x:+] [x:+] [x:-] [x:-0] [x:-0]

[x:0] [x:+] [x:0+] [x:-][x:+] [x:+] [x:0+] [x:-0]

Functional approach: Separate analysis for each input abstract state.

Saturday, 8 June 13

Page 22: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc(); 7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:+] [x:+] [x:+] [x:-] [x:-0] [x:-0]

[x:0] [x:+] [x:0+] [x:-][x:+] [x:+] [x:0+] [x:-0]

Functional approach: Separate analysis for each input abstract state.

Saturday, 8 June 13

Page 23: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc(); 7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:+] [x:+] [x:+] [x:-] [x:-0] [x:-0]

[x:0] [x:+] [x:0+] [x:-][x:+] [x:+] [x:0+] [x:-0]

Functional approach: Separate analysis for each input abstract state.

Saturday, 8 June 13

Page 24: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc(); 7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:+] [x:+] [x:+] [x:-] [x:-0] [x:-0]

[x:0] [x:+] [x:0+] [x:-][x:+] [x:+] [x:0+] [x:-0]

Functional approach: Separate analysis for each input abstract state.

Saturday, 8 June 13

Page 25: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc(); 7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:+] [x:+] [x:+] [x:-] [x:-0] [x:-0]

[x:0] [x:+] [x:0+] [x:-][x:+] [x:+] [x:0+] [x:-0]

Functional approach: Separate analysis for each input abstract state.

Saturday, 8 June 13

Page 26: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc(); 7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:+] [x:+] [x:+] [x:-] [x:-0] [x:-0]

[x:0] [x:0+] [x:-][x:+] [x:+] [x:-0]

Functional approach: Separate analysis for each input abstract state.

Saturday, 8 June 13

Page 27: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc(); 7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:+] [x:+] [x:+] [x:-] [x:-0] [x:-0]

[x:0] [x:0+] [x:-][x:+] [x:+] [x:-0]

Functional approach: Separate analysis for each input abstract state.

Saturday, 8 June 13

Page 28: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc(); 7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:0+] [x:+] [x:+] [x:-] [x:-0] [x:-0]

[x:0] [x:0+] [x:-][x:+] [x:+] [x:-0]

Functional approach: Separate analysis for each input abstract state.

Saturday, 8 June 13

Page 29: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc(); 7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:0+] [x:+] [x:+] [x:-] [x:-0] [x:-0]

[x:0] [x:0+] [x:-][x:+] [x:+] [x:-0]

Functional approach: Separate analysis for each input abstract state.

Saturday, 8 June 13

Page 30: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc(); 7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:0+] [x:+] [x:+] [x:-] [x:-0] [x:-0]

[x:0] [x:0+] [x:-][x:+] [x:+] [x:-0]

Functional approach: Separate analysis for each input abstract state.

Saturday, 8 June 13

Page 31: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc(); 7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:0+] [x:+] [x:+] [x:-] [x:-0] [x:-0]

[x:0] [x:0+] [x:-][x:+] [x:+] [x:-0]

Functional approach: Separate analysis for each input abstract state.

Saturday, 8 June 13

Page 32: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc(); 7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:0+] [x:+] [x:+] [x:-] [x:-0] [x:-0]

[x:0] [x:0+] [x:-][x:+] [x:+] [x:-0]

Functional approach: Separate analysis for each input abstract state.

Saturday, 8 June 13

Page 33: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc(); 7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:0+] [x:+] [x:+] [x:-] [x:-0] [x:-0]

[x:0] [x:0+] [x:-][x:+] [x:+] [x:-0]

Functional approach: Separate analysis for each input abstract state.

Saturday, 8 June 13

Page 34: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc(); 7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:0+] [x:+] [x:+] [x:-] [x:-0] [x:-0]

[x:0] [x:0+] [x:-][x:+] [x:+] [x:-0]

Functional approach: Separate analysis for each input abstract state.

Saturday, 8 June 13

Page 35: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc(); 7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:0+] [x:+] [x:+] [x:-] [x:-0] [x:-0]

[x:0] [x:0+] [x:-][x:+] [x:+] [x:-0]

Functional approach: Separate analysis for each input abstract state.

Saturday, 8 June 13

Page 36: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc(); 7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:0+] [x:+] [x:+] [x:-] [x:-0] [x:-0]

[x:0] [x:0+] [x:-][x:+] [x:+] [x:-0]

Functional approach: Separate analysis for each input abstract state.

Proved the first query.

Saturday, 8 June 13

Page 37: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc(); 7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:0+] [x:+] [x:+] [x:-] [x:-0] [x:-0]

[x:0] [x:0+] [x:-][x:+] [x:+] [x:-0]

Functional approach: Separate analysis for each input abstract state.

Proved the first query.Computed a summary of inc().

Saturday, 8 June 13

Page 38: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc(); 7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:0+] [x:+] [x:+] [x:-] [x:-0] [x:-0]

[x:0] [x:0+] [x:-] [x:⊤] [x:⊥][x:+] [x:+] [x:-0] ??? ???

Functional approach: Separate analysis for each input abstract state.

Proved the first query.Computed a summary of inc(). But something strange.

Lack of monotonicity.

Saturday, 8 June 13

Page 39: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc(); 7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:0+] [x:+] [x:+] [x:-] [x:-0] [x:-0]

[x:0] [x:0+] [x:-] [x:+] [x:+] [x:-0]

Functional approach: Separate analysis for each input abstract state.

Proved the first query.Computed a summary of inc(). But something strange.

Unused entry.Difficult to see it as the least solution.

Saturday, 8 June 13

Page 40: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc(); 7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:0+] [x:+] [x:+] [x:-] [x:-0] [x:-0]

[x:0] [x:0+] [x:-] [x:+] [x:+] [x:-0]

Functional approach: Separate analysis for each input abstract state.

Proved the first query.Computed a summary of inc(). But something strange.

Unused entry.Difficult to see it as the least solution.

Saturday, 8 June 13

Page 41: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc();7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

Callstring approach: Separate analysis for each call string (call site here).

Saturday, 8 June 13

Page 42: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc();7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:+] [x:0+] [x:+] [x:-] [x:-0] [x:-0]

3:[x:⊥] 5:[x:⊥] 8:[x:⊥] [x:⊥] [x:⊥] [x:⊥]

Callstring approach: Separate analysis for each call string (call site here).

Saturday, 8 June 13

Page 43: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc();7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:+] [x:0+] [x:+] [x:-] [x:-0] [x:-0]

3:[x:⊥] 5:[x:⊥] 8:[x:⊥] [x:⊥] [x:⊥] [x:⊥]

Callstring approach: Separate analysis for each call string (call site here).

Saturday, 8 June 13

Page 44: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc();7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:+] [x:0+] [x:+] [x:-] [x:-0] [x:-0]

3:[x:0] 5:[x:⊥] 8:[x:⊥] [x:⊥] [x:⊥] [x:⊥]

Callstring approach: Separate analysis for each call string (call site here).

Saturday, 8 June 13

Page 45: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc();7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:+] [x:0+] [x:+] [x:-] [x:-0] [x:-0]

3:[x:0] 5:[x:⊥] 8:[x:⊥] [x:+] [x:⊥] [x:⊥]

Callstring approach: Separate analysis for each call string (call site here).

Saturday, 8 June 13

Page 46: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc();7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:+] [x:0+] [x:+] [x:-] [x:-0] [x:-0]

3:[x:0] 5:[x:⊥] 8:[x:⊥] [x:+] [x:⊥] [x:⊥]

Callstring approach: Separate analysis for each call string (call site here).

Saturday, 8 June 13

Page 47: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc();7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:+] [x:0+] [x:+] [x:-] [x:-0] [x:-0]

3:[x:0] 5:[x:⊥] 8:[x:⊥] [x:+] [x:⊥] [x:⊥]

Callstring approach: Separate analysis for each call string (call site here).

Saturday, 8 June 13

Page 48: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc();7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:+] [x:0+] [x:+] [x:-] [x:-0] [x:-0]

3:[x:0] 5:[x:⊥] 8:[x:⊥] [x:+] [x:⊥] [x:⊥]

Callstring approach: Separate analysis for each call string (call site here).

Saturday, 8 June 13

Page 49: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc();7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:+] [x:0+] [x:+] [x:-] [x:-0] [x:-0]

3:[x:0+] 5:[x:⊥] 8:[x:⊥] [x:+] [x:⊥] [x:⊥]

Callstring approach: Separate analysis for each call string (call site here).

Saturday, 8 June 13

Page 50: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc();7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:+] [x:0+] [x:+] [x:-] [x:-0] [x:-0]

3:[x:0+] 5:[x:⊥] 8:[x:⊥] [x:+] [x:⊥] [x:⊥]

Callstring approach: Separate analysis for each call string (call site here).

Saturday, 8 June 13

Page 51: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc();7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:+] [x:0+] [x:+] [x:-] [x:-0] [x:-0]

3:[x:0+] 5:[x:⊥] 8:[x:⊥] [x:+] [x:⊥] [x:⊥]

Callstring approach: Separate analysis for each call string (call site here).

Saturday, 8 June 13

Page 52: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc();7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:0+] [x:0+] [x:+] [x:-] [x:-0] [x:-0]

3:[x:0+] 5:[x:⊥] 8:[x:⊥] [x:+] [x:⊥] [x:⊥]

Callstring approach: Separate analysis for each call string (call site here).

Saturday, 8 June 13

Page 53: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc();7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:0+] [x:0+] [x:+] [x:-] [x:-0] [x:-0]

3:[x:0+] 5:[x:0+] 8:[x:⊥] [x:+] [x:⊥] [x:⊥]

Callstring approach: Separate analysis for each call string (call site here).

Saturday, 8 June 13

Page 54: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc();7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:0+] [x:+] [x:+] [x:-] [x:-0] [x:-0]

3:[x:0+] 5:[x:0+] 8:[x:⊥] [x:+] [x:+] [x:⊥]

Callstring approach: Separate analysis for each call string (call site here).

Saturday, 8 June 13

Page 55: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc();7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:0+] [x:+] [x:+] [x:-] [x:-0] [x:-0]

3:[x:0+] 5:[x:0+] 8:[x:⊥] [x:+] [x:+] [x:⊥]

Callstring approach: Separate analysis for each call string (call site here).

Saturday, 8 June 13

Page 56: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc();7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:0+] [x:+] [x:+] [x:-] [x:-0] [x:-0]

3:[x:0+] 5:[x:0+] 8:[x:⊥] [x:+] [x:+] [x:⊥]

Callstring approach: Separate analysis for each call string (call site here).

Saturday, 8 June 13

Page 57: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc();7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:0+] [x:+] [x:+] [x:-] [x:-0] [x:-0]

3:[x:0+] 5:[x:0+] 8:[x:-] [x:+] [x:+] [x:⊥]

Callstring approach: Separate analysis for each call string (call site here).

Saturday, 8 June 13

Page 58: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc();7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:0+] [x:+] [x:+] [x:-] [x:-0] [x:-0]

3:[x:0+] 5:[x:0+] 8:[x:-] [x:+] [x:+] [x:-0]

Callstring approach: Separate analysis for each call string (call site here).

Saturday, 8 June 13

Page 59: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc();7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:0+] [x:+] [x:+] [x:-] [x:-0] [x:-0]

3:[x:0+] 5:[x:0+] 8:[x:-] [x:+] [x:+] [x:-0]

Callstring approach: Separate analysis for each call string (call site here).

Saturday, 8 June 13

Page 60: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc();7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:0+] [x:+] [x:+] [x:-] [x:-0] [x:-0]

3:[x:0+] 5:[x:0+] 8:[x:-] [x:+] [x:+] [x:-0]

Callstring approach: Separate analysis for each call string (call site here).

Saturday, 8 June 13

Page 61: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc();7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:0+] [x:+] [x:+] [x:-] [x:-0] [x:-0]

3:[x:0+] 5:[x:0+] 8:[x:-] [x:+] [x:+] [x:-0]

Callstring approach: Separate analysis for each call string (call site here).

Proved the first query. Same result for main as before.Computed a summary of inc().

Saturday, 8 June 13

Page 62: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc();7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:0+] [x:+] [x:+] [x:-] [x:-0] [x:-0]

3:[x:0+] 5:[x:0+] 8:[x:-] [x:+] [x:+] [x:-0]

Callstring approach: Separate analysis for each call string (call site here).

Proved the first query. Same result for main as before.A summary of inc() as a map from labels to results.

Saturday, 8 June 13

Page 63: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc();7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[x:⊤][x:0][x:0] [x:0+][x:+] [x:+][x:+] [x:0+] [x:+] [x:+] [x:-] [x:-0] [x:-0]

3:[x:0+] 5:[x:0+] 8:[x:-] [x:+] [x:+] [x:-0]

Callstring approach: Separate analysis for each call string (call site here).

Proved the first query. Same result for main as before.A summary of inc() as a map from labels to results.

Nothing strange.Least fixpoint.

But some redundancy.

Saturday, 8 June 13

Page 64: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

How are functional and callstring approaches related?

Saturday, 8 June 13

Page 65: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc(); 7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

Summary by fun. approach σ:[x:0] [x:0+] [x:-][x:+] [x:+] [x:-0]

Analysis results for main by both approaches:

1: [x:⊤]2: [x:0]3: [x:0+]4: [x:+]5: [x:0+]6: [x:+]7: [x:+]8: [x:-] 9: [x:-0]10: [x:-0]

Summary by call. approach κ:3:[x:+] 5:[x:+] 8:[x:-0]

How are functional and callstring approaches related?

Saturday, 8 June 13

Page 66: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x;1: void main() { 2: x = 0;3: while (*) { 4: inc();5: }6: inc(); 7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

Summary by fun. approach σ:[x:0] [x:0+] [x:-][x:+] [x:+] [x:-0]

Analysis results for main by both approaches:

1: [x:⊤]2: [x:0]3: [x:0+]4: [x:+]5: [x:0+]6: [x:+]7: [x:+]8: [x:-] 9: [x:-0]10: [x:-0]

Summary by call. approach κ:3:[x:+] 5:[x:+] 8:[x:-0]

How are functional and callstring approaches related?Function η: 3:[x:0+] 5:[x:0+] 8:[x:-] Relationship: κ = σ o η

Saturday, 8 June 13

Page 67: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

ProgramLocation x CallString

ProgramLocation x AbstractState

AbstractState

κ

σ

λ(pc,s). (pc, η(pc,s))

Saturday, 8 June 13

Page 68: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

ProgramLocation x CallString

ProgramLocation x AbstractState

AbstractState

κ

σ

λ(pc,s). (pc, η(pc,s))

Functional approach

Saturday, 8 June 13

Page 69: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

ProgramLocation x CallString

ProgramLocation x AbstractState

AbstractState

κ

σ

λ(pc,s). (pc, η(pc,s))

Callstring approach

Saturday, 8 June 13

Page 70: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

ProgramLocation x CallString

ProgramLocation x AbstractState

AbstractState

κ

σ

λ(pc,s). (pc, η(pc,s))

Defined from σ by finding an abstract state for each callstring.

Saturday, 8 June 13

Page 71: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

ProgramLocation x CallString

ProgramLocation x AbstractState

AbstractState

κ

σ

λ(pc,s). (pc, η(pc,s))

Finite in many cases

Always infinite

Saturday, 8 June 13

Page 72: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

ProgramLocation x CallString

ProgramLocation x AbstractState

AbstractState

κ

σ

λ(pc,s). (pc, η(pc,s))

Finite in many cases

Always infinite

This gives an algorithm for doing callstring-based fully context-sensitive analysis.

Saturday, 8 June 13

Page 73: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

ProgramLocation x CallString

ProgramLocation x AbstractState

AbstractState

κ

σ

λ(pc,s). (pc, η(pc,s))

Sharir & Pnueli proved for path-sensitive analyses.We generalised it for non path-sensitive analyses. Different proof techniques are needed.

Saturday, 8 June 13

Page 74: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

Some further words

• Dominance relation in the result of function approach.

• Equivalence after garbage collection.

Saturday, 8 June 13

Page 75: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

Experimental results

0CFAI 1CFAI 2CFAI 0CFAS SBASantlr 1m45s 40m 72m 23m 21mavrora 1m42s 38m 68m 26m 17mbloat 3m10s 82m 239m 38m 60mchart 4m40s 121m 256m 30m 51mhsqldb 3m29s 74m 158m 34m 37mluindex 2m34s 41m 83m 35m 27mlusearch 2m22s 43m 80m 24m 16mpmd 3m52s 61m 112m 34m 29msunflow 5m00s 148m 279m 58m 72mxalan 2m32s 36m 82m 23m 16m

Table 3: Running times of the approaches from Table 1(b).

combined points-to and call graph analysis, it need not necessarilyhelp other clients like monomorphic call sites.

5.2.3 ScalabilityNext, we compare the performance of the different approaches. Ta-ble 3 shows their running times, exclusive of the client runningtimes. The running time increases from 0CFAI to 2CFAI with largedifferences between the different flow insensitive approaches. Also,the running time of 0CFAS2 and SBAS2 is shorter, compared to0CFAS and SBAS respectively. This is an artifact of the latter anal-yses performing heap updates context sensitively. Context sensitiveupdates requires 0CFAS and SBAS to call the tabulation algorithmmultiple times, leading to longer running time. Furthermore, thealmost equivalent running times for the flow sensitive versions of0-CFA and the summary-based versions can be attributed to theuse of the tabulation algorithm with almost identical implementa-tion for both. Finally, across all the benchmarks, SBAS runs signif-icantly faster than 2CFAI.

The improved performance of SBAS over 2CFAI can be ex-plained with the help of the information about the number ofmethod contexts in Table 4. The table shows the total number ofdistinct method contexts as computed by the different approachesfor each benchmark. The key result here is that 2CFAI computesalmost 4X-7X more contexts per benchmark than SBAS which, asexplained in Section 2, implies that the summary-based techniqueused by SBAS is able to merge multiple call string contexts. Dueto the correlation between the number of contexts and the num-ber of times a method is analyzed, more contexts correspond to alonger running time, explaining the slower performance of 2CFAIcompared to SBAS. The substantial increase in running time from0CFAI to 2CFAI can also be attributed to the large increase in thenumber of method contexts across these analysis approaches. Fur-ther, as the rate of increase in the number of method contexts from0CFAI to 2CFAI suggests, approaches with k � 3 compute toomany contexts and run out of memory.

6. Related WorkThis section surveys related work on the summary-based andcloning-based approaches to top-down interprocedural static analy-sis, including both precision and scalability results and some equiv-alence results between these separate approaches.

Summary-based Interprocedural Analysis. Sharir and Pnueli[19] first proposed using functional summaries to solve interpro-cedural dataflow problems in a precise context sensitive manner.Later, Reps et al. [17] proposed a context and flow sensitive, inter-procedural tabulation algorithm based on CFL-reachability to solvea specific class of dataflow problems. More recently, many demand-driven CFL reachability algorithms [6, 22, 31] have been proposedfor various program analyses, including alias and points-to analy-ses. Xu et al. [30] extend the CFL-reachability points-to analysis in[22] by adding a pre-pass for scalability. Ball and Rajamani [1] useBDDs to compactly represent results of the tabulation algorithm.

0

1

2

3

4

5

6

7

0 2 4 6 8 10 12

antlr

0CFA

I

H

2CFA

I

H

SBA

S

H

0

1

2

3

4

5

6

7

0 2 4 6 8 10 12 14 16

avrora

0

2

4

6

8

10

0 2 4 6 8 10 12 14

bloat

0

2

4

6

8

10

12

0 5 10 15 20 25 30

chart

0

2

4

6

8

10

0 2 4 6 8 10 12 14

hsqldb

0

1

2

3

4

5

6

7

0 2 4 6 8 10 12

luindex

0

1

2

3

4

5

6

7

0 2 4 6 8 10 12

lusearch

0

2

4

6

8

10

0 2 4 6 8 10 12 14 16 18 20

pmd

0

2

4

6

8

10

12

14

0 5 10 15 20 25

sunflow

0

1

2

3

4

5

6

7

0 2 4 6 8 10 12 14 16 18

xalan

Figure 9: Distribution of the number of methods reachable fromeach method. Both axes show numbers of methods in thousands.

In contrast, our implementation of the summary-based analysis, isneither demand-driven nor uses symbolic representations such asBDDs. Instead, we use the lossy join operator to tame scalability.

Cloning-based Interprocedural Analysis. There is a largebody of work on bounded call-string-like analyses we collectivelycall k-limited analyses. Besides k-CFA [20], another popular suchanalysis is k-object sensitive analysis for object-oriented programs[14, 21]. Many recent works express k-limited points-to and call-graph analyses in Datalog, a declarative logic programming lan-guage, and solve them using specialized Datalog solvers [3, 27].These solvers exploit redundancy arising from large numbers ofsimilar contexts computed by k-limited analyses for high k val-ues. They either use Binary Decision Diagrams (BDDs), which aresymbolic (graph-based) representations of boolean functions, torepresent and manipulate analysis results [2, 9, 28, 32], or explicitrepresentations and algorithms from the databases literature [3]. Xuand Rountev [29] propose a call-string-based technique with heap-cloning that merges equivalent analysis contexts in order to scale.Other works [4, 11, 16] propose client-driven refinement of the in-terprocedural analysis precision, in order to scale effectively. All

9

Saturday, 8 June 13

Page 76: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

Experimental results

0CFAI 1CFAI 2CFAI 0CFAS SBASantlr 1m45s 40m 72m 23m 21mavrora 1m42s 38m 68m 26m 17mbloat 3m10s 82m 239m 38m 60mchart 4m40s 121m 256m 30m 51mhsqldb 3m29s 74m 158m 34m 37mluindex 2m34s 41m 83m 35m 27mlusearch 2m22s 43m 80m 24m 16mpmd 3m52s 61m 112m 34m 29msunflow 5m00s 148m 279m 58m 72mxalan 2m32s 36m 82m 23m 16m

Table 3: Running times of the approaches from Table 1(b).

combined points-to and call graph analysis, it need not necessarilyhelp other clients like monomorphic call sites.

5.2.3 ScalabilityNext, we compare the performance of the different approaches. Ta-ble 3 shows their running times, exclusive of the client runningtimes. The running time increases from 0CFAI to 2CFAI with largedifferences between the different flow insensitive approaches. Also,the running time of 0CFAS2 and SBAS2 is shorter, compared to0CFAS and SBAS respectively. This is an artifact of the latter anal-yses performing heap updates context sensitively. Context sensitiveupdates requires 0CFAS and SBAS to call the tabulation algorithmmultiple times, leading to longer running time. Furthermore, thealmost equivalent running times for the flow sensitive versions of0-CFA and the summary-based versions can be attributed to theuse of the tabulation algorithm with almost identical implementa-tion for both. Finally, across all the benchmarks, SBAS runs signif-icantly faster than 2CFAI.

The improved performance of SBAS over 2CFAI can be ex-plained with the help of the information about the number ofmethod contexts in Table 4. The table shows the total number ofdistinct method contexts as computed by the different approachesfor each benchmark. The key result here is that 2CFAI computesalmost 4X-7X more contexts per benchmark than SBAS which, asexplained in Section 2, implies that the summary-based techniqueused by SBAS is able to merge multiple call string contexts. Dueto the correlation between the number of contexts and the num-ber of times a method is analyzed, more contexts correspond to alonger running time, explaining the slower performance of 2CFAIcompared to SBAS. The substantial increase in running time from0CFAI to 2CFAI can also be attributed to the large increase in thenumber of method contexts across these analysis approaches. Fur-ther, as the rate of increase in the number of method contexts from0CFAI to 2CFAI suggests, approaches with k � 3 compute toomany contexts and run out of memory.

6. Related WorkThis section surveys related work on the summary-based andcloning-based approaches to top-down interprocedural static analy-sis, including both precision and scalability results and some equiv-alence results between these separate approaches.

Summary-based Interprocedural Analysis. Sharir and Pnueli[19] first proposed using functional summaries to solve interpro-cedural dataflow problems in a precise context sensitive manner.Later, Reps et al. [17] proposed a context and flow sensitive, inter-procedural tabulation algorithm based on CFL-reachability to solvea specific class of dataflow problems. More recently, many demand-driven CFL reachability algorithms [6, 22, 31] have been proposedfor various program analyses, including alias and points-to analy-ses. Xu et al. [30] extend the CFL-reachability points-to analysis in[22] by adding a pre-pass for scalability. Ball and Rajamani [1] useBDDs to compactly represent results of the tabulation algorithm.

0

1

2

3

4

5

6

7

0 2 4 6 8 10 12

antlr

0CFA

I

H

2CFA

I

H

SBA

S

H

0

1

2

3

4

5

6

7

0 2 4 6 8 10 12 14 16

avrora

0

2

4

6

8

10

0 2 4 6 8 10 12 14

bloat

0

2

4

6

8

10

12

0 5 10 15 20 25 30

chart

0

2

4

6

8

10

0 2 4 6 8 10 12 14

hsqldb

0

1

2

3

4

5

6

7

0 2 4 6 8 10 12

luindex

0

1

2

3

4

5

6

7

0 2 4 6 8 10 12

lusearch

0

2

4

6

8

10

0 2 4 6 8 10 12 14 16 18 20

pmd

0

2

4

6

8

10

12

14

0 5 10 15 20 25

sunflow

0

1

2

3

4

5

6

7

0 2 4 6 8 10 12 14 16 18

xalan

Figure 9: Distribution of the number of methods reachable fromeach method. Both axes show numbers of methods in thousands.

In contrast, our implementation of the summary-based analysis, isneither demand-driven nor uses symbolic representations such asBDDs. Instead, we use the lossy join operator to tame scalability.

Cloning-based Interprocedural Analysis. There is a largebody of work on bounded call-string-like analyses we collectivelycall k-limited analyses. Besides k-CFA [20], another popular suchanalysis is k-object sensitive analysis for object-oriented programs[14, 21]. Many recent works express k-limited points-to and call-graph analyses in Datalog, a declarative logic programming lan-guage, and solve them using specialized Datalog solvers [3, 27].These solvers exploit redundancy arising from large numbers ofsimilar contexts computed by k-limited analyses for high k val-ues. They either use Binary Decision Diagrams (BDDs), which aresymbolic (graph-based) representations of boolean functions, torepresent and manipulate analysis results [2, 9, 28, 32], or explicitrepresentations and algorithms from the databases literature [3]. Xuand Rountev [29] propose a call-string-based technique with heap-cloning that merges equivalent analysis contexts in order to scale.Other works [4, 11, 16] propose client-driven refinement of the in-terprocedural analysis precision, in order to scale effectively. All

9

Functional approach

Saturday, 8 June 13

Page 77: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

Experimental results

0CFAI 1CFAI 2CFAI 0CFAS SBASantlr 1m45s 40m 72m 23m 21mavrora 1m42s 38m 68m 26m 17mbloat 3m10s 82m 239m 38m 60mchart 4m40s 121m 256m 30m 51mhsqldb 3m29s 74m 158m 34m 37mluindex 2m34s 41m 83m 35m 27mlusearch 2m22s 43m 80m 24m 16mpmd 3m52s 61m 112m 34m 29msunflow 5m00s 148m 279m 58m 72mxalan 2m32s 36m 82m 23m 16m

Table 3: Running times of the approaches from Table 1(b).

combined points-to and call graph analysis, it need not necessarilyhelp other clients like monomorphic call sites.

5.2.3 ScalabilityNext, we compare the performance of the different approaches. Ta-ble 3 shows their running times, exclusive of the client runningtimes. The running time increases from 0CFAI to 2CFAI with largedifferences between the different flow insensitive approaches. Also,the running time of 0CFAS2 and SBAS2 is shorter, compared to0CFAS and SBAS respectively. This is an artifact of the latter anal-yses performing heap updates context sensitively. Context sensitiveupdates requires 0CFAS and SBAS to call the tabulation algorithmmultiple times, leading to longer running time. Furthermore, thealmost equivalent running times for the flow sensitive versions of0-CFA and the summary-based versions can be attributed to theuse of the tabulation algorithm with almost identical implementa-tion for both. Finally, across all the benchmarks, SBAS runs signif-icantly faster than 2CFAI.

The improved performance of SBAS over 2CFAI can be ex-plained with the help of the information about the number ofmethod contexts in Table 4. The table shows the total number ofdistinct method contexts as computed by the different approachesfor each benchmark. The key result here is that 2CFAI computesalmost 4X-7X more contexts per benchmark than SBAS which, asexplained in Section 2, implies that the summary-based techniqueused by SBAS is able to merge multiple call string contexts. Dueto the correlation between the number of contexts and the num-ber of times a method is analyzed, more contexts correspond to alonger running time, explaining the slower performance of 2CFAIcompared to SBAS. The substantial increase in running time from0CFAI to 2CFAI can also be attributed to the large increase in thenumber of method contexts across these analysis approaches. Fur-ther, as the rate of increase in the number of method contexts from0CFAI to 2CFAI suggests, approaches with k � 3 compute toomany contexts and run out of memory.

6. Related WorkThis section surveys related work on the summary-based andcloning-based approaches to top-down interprocedural static analy-sis, including both precision and scalability results and some equiv-alence results between these separate approaches.

Summary-based Interprocedural Analysis. Sharir and Pnueli[19] first proposed using functional summaries to solve interpro-cedural dataflow problems in a precise context sensitive manner.Later, Reps et al. [17] proposed a context and flow sensitive, inter-procedural tabulation algorithm based on CFL-reachability to solvea specific class of dataflow problems. More recently, many demand-driven CFL reachability algorithms [6, 22, 31] have been proposedfor various program analyses, including alias and points-to analy-ses. Xu et al. [30] extend the CFL-reachability points-to analysis in[22] by adding a pre-pass for scalability. Ball and Rajamani [1] useBDDs to compactly represent results of the tabulation algorithm.

0

1

2

3

4

5

6

7

0 2 4 6 8 10 12

antlr

0CFA

I

H

2CFA

I

H

SBA

S

H

0

1

2

3

4

5

6

7

0 2 4 6 8 10 12 14 16

avrora

0

2

4

6

8

10

0 2 4 6 8 10 12 14

bloat

0

2

4

6

8

10

12

0 5 10 15 20 25 30

chart

0

2

4

6

8

10

0 2 4 6 8 10 12 14

hsqldb

0

1

2

3

4

5

6

7

0 2 4 6 8 10 12

luindex

0

1

2

3

4

5

6

7

0 2 4 6 8 10 12

lusearch

0

2

4

6

8

10

0 2 4 6 8 10 12 14 16 18 20

pmd

0

2

4

6

8

10

12

14

0 5 10 15 20 25

sunflow

0

1

2

3

4

5

6

7

0 2 4 6 8 10 12 14 16 18

xalan

Figure 9: Distribution of the number of methods reachable fromeach method. Both axes show numbers of methods in thousands.

In contrast, our implementation of the summary-based analysis, isneither demand-driven nor uses symbolic representations such asBDDs. Instead, we use the lossy join operator to tame scalability.

Cloning-based Interprocedural Analysis. There is a largebody of work on bounded call-string-like analyses we collectivelycall k-limited analyses. Besides k-CFA [20], another popular suchanalysis is k-object sensitive analysis for object-oriented programs[14, 21]. Many recent works express k-limited points-to and call-graph analyses in Datalog, a declarative logic programming lan-guage, and solve them using specialized Datalog solvers [3, 27].These solvers exploit redundancy arising from large numbers ofsimilar contexts computed by k-limited analyses for high k val-ues. They either use Binary Decision Diagrams (BDDs), which aresymbolic (graph-based) representations of boolean functions, torepresent and manipulate analysis results [2, 9, 28, 32], or explicitrepresentations and algorithms from the databases literature [3]. Xuand Rountev [29] propose a call-string-based technique with heap-cloning that merges equivalent analysis contexts in order to scale.Other works [4, 11, 16] propose client-driven refinement of the in-terprocedural analysis precision, in order to scale effectively. All

9

Functional approach

Approximate callstring approach

Saturday, 8 June 13

Page 78: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x = -10;1: void main() { 2: while (*) { 3: inc();4: }5: x = 0;6: inc(); 7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

Saturday, 8 June 13

Page 79: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x = -10;1: void main() { 2: while (*) { 3: inc();4: }5: x = 0;6: inc(); 7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[Q] Which one should we treat context-sensitively (i.e. inline)?

1. Line 62. Line 93. Lines 6,94. Lines 3,6,9

Saturday, 8 June 13

Page 80: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x = -10;1: void main() { 2: while (*) { 3: inc();4: }5: x = 0;6: inc(); 7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[Q] Which one should we treat context-sensitively (i.e. inline)?

1. Line 62. Line 93. Lines 6,94. Lines 3,6,9

Saturday, 8 June 13

Page 81: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x = -10;1: void main() { 2: while (*) { 3: inc();4: }5: x = 0;6: x++; 7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[Q] Which one should we treat context-sensitively (i.e. inline)?

1. Line 62. Line 93. Lines 6,94. Lines 3,6,9

Saturday, 8 June 13

Page 82: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x = -10;1: void main() { 2: while (*) { 3: inc();4: }5: x = 0; // [x:0]6: x++; // [x:+]7: assert(x > 0);8: x = -x; 9: inc();10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[Q] Which one should we treat context-sensitively (i.e. inline)?

1. Line 62. Line 93. Lines 6,94. Lines 3,6,9

Saturday, 8 June 13

Page 83: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x = -10;1: void main() { 2: while (*) { 3: inc();4: }5: x = 0; // [x:0]6: x++; // [x:+]7: assert(x > 0);8: x = -x; 9: x++;10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[Q] Which one should we treat context-sensitively (i.e. inline)?

1. Line 62. Line 93. Lines 6,94. Lines 3,6,9

Saturday, 8 June 13

Page 84: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x = -10;1: void main() { 2: while (*) { 3: inc();4: }5: x = 0; // [x:0]6: x++; // [x:+]7: assert(x > 0);8: x = -x;// [x:-] 9: x++; // [x:-0]10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[Q] Which one should we treat context-sensitively (i.e. inline)?

1. Line 62. Line 93. Lines 6,94. Lines 3,6,9

Saturday, 8 June 13

Page 85: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x = -10;1: void main() { 2: while (*) { 3: inc();4: }5: x = 0; // [x:0]6: x++; // [x:+]7: assert(x > 0);8: x = -x;// [x:-] 9: x++; // [x:-0]10: assert(x >= 0);11: }12:13: void inc() {14: x++;15: }

[Q] Which one should we treat context-sensitively (i.e. inline)?

1. Line 62. Line 93. Lines 6,94. Lines 3,6,9

We want to predict where context-sensitivity would help, without running the context-sensitive analysis.

Saturday, 8 June 13

Page 86: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

• Further abstraction of abstract values.

0

-0

- +

0+

⊥0+

New value domain

Old value domain

Approximate a static analysis

Saturday, 8 June 13

Page 87: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

• Further abstraction of abstract values.

New value domain

Old value domain

0

-0

- +

0+

⊥0+

meaning fn γ

Approximate a static analysis

Saturday, 8 June 13

Page 88: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

• Further abstraction of abstract values.

New value domain

Old value domain

0

-0

- +

0+

⊥0+

meaning fn γ

Approximate a static analysis

Saturday, 8 June 13

Page 89: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

Approximate a static analysis

• Further abstraction of transfer functions:

(γ o ⟦x=x+y⟧new)a ⊒ (⟦x=x+y⟧old o γ)a

• Use transfer functions of particular form only:

⟦x=x+y⟧new a = a[x: a(x) ⊔ a(y)]

• This restriction ensures an efficient algorithm for doing a fully context-sensitive analysis.

Saturday, 8 June 13

Page 90: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

Approximate queries

• Express queries using new abstract states.

• Replace x>0 by x>=0 (i.e., a(x)=0+).

0: int x = -10;1: void main() { 2: while (*) {3: inc();4: }5: x = 0;6: inc();7: assert(x > 0);8: x = -x;9: inc();10: assert(x >= 0);11: }

0: int x = -10;1: void main() { 2: while (*) {3: inc();4: }5: x = 0;6: inc();7: assert(x >= 0);8: x = -x;9: inc();10: assert(x >= 0);11: }

Saturday, 8 June 13

Page 91: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x = -10;1: void main() { 2: while (*) { // [x:⊤]3: inc(); // [x:⊤]4: } // [x:⊤]5: x = 0; // [x:0+]6: inc(); // [x:0+] 7: assert(x >= 0);8: x = -x; // [x:⊤]9: inc(); // [x:⊤]10: assert(x >= 0);11: }12:13: void inc() { // [x:0+] [x:⊤]14: x++; // [x:0+] [x:⊤]15: }

Saturday, 8 June 13

Page 92: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x = -10;1: void main() { 2: while (*) { // [x:⊤]3: inc(); // [x:⊤]4: } // [x:⊤]5: x = 0; // [x:0+]6: inc(); // [x:0+] 7: assert(x >= 0);8: x = -x; // [x:⊤]9: inc(); // [x:⊤]10: assert(x >= 0);11: }12:13: void inc() { // [x:0+] [x:⊤]14: x++; // [x:0+] [x:⊤]15: }

Saturday, 8 June 13

Page 93: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x = -10;1: void main() { 2: while (*) { // [x:⊤]3: inc(); // [x:⊤]4: } // [x:⊤]5: x = 0; // [x:0+]6: inc(); // [x:0+] 7: assert(x >= 0);8: x = -x; // [x:⊤]9: inc(); // [x:⊤]10: assert(x >= 0);11: }12:13: void inc() { // [x:0+] [x:⊤]14: x++; // [x:0+] [x:⊤]15: }

Saturday, 8 June 13

Page 94: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x = -10;1: void main() { 2: while (*) { // [x:⊤]3: inc(); // [x:⊤]4: } // [x:⊤]5: x = 0; // [x:0+]6: inc(); // [x:0+] 7: assert(x >= 0);8: x = -x; // [x:⊤]9: inc(); // [x:⊤]10: assert(x >= 0);11: }12:13: void inc() { // [x:0+] [x:⊤]14: x++; // [x:0+] [x:⊤]15: }

Saturday, 8 June 13

Page 95: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x = -10;1: void main() { 2: while (*) { // [x:⊤]3: inc(); // [x:⊤]4: } // [x:⊤]5: x = 0; // [x:0+]6: inc(); // [x:0+] 7: assert(x >= 0);8: x = -x; // [x:⊤]9: inc(); // [x:⊤]10: assert(x >= 0);11: }12:13: void inc() { // [x:0+] [x:⊤]14: x++; // [x:0+] [x:⊤]15: }

1) Collect all the proved approximate queries.2) For such queries, find relevant procedure calls.3) All those calls should be treated context-sensitively.

Saturday, 8 June 13

Page 96: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x = -10;1: void main() { 2: while (*) { // [x:⊤]3: inc(); // [x:⊤]4: } // [x:⊤]5: x = 0; // [x:0+]6: inc(); // [x:0+] 7: assert(x >= 0);8: x = -x; // [x:⊤]9: inc(); // [x:⊤]10: assert(x >= 0);11: }12:13: void inc() { // [x:0+] [x:⊤]14: x++; // [x:0+] [x:⊤]15: }

1) Collect all the proved approximate queries.2) For such queries, find relevant procedure calls.3) All those calls should be treated context-sensitively.

Saturday, 8 June 13

Page 97: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x = -10;1: void main() { 2: while (*) { // [x:⊤]3: inc(); // [x:⊤]4: } // [x:⊤]5: x = 0; // [x:0+]6: inc(); // [x:0+] 7: assert(x >= 0);8: x = -x; // [x:⊤]9: inc(); // [x:⊤]10: assert(x >= 0);11: }12:13: void inc() { // [x:0+] [x:⊤]14: x++; // [x:0+] [x:⊤]15: }

1) Collect all the proved approximate queries.2) For such queries, find relevant procedure calls.3) All those calls should be treated context-sensitively.

Saturday, 8 June 13

Page 98: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x = -10;1: void main() { 2: while (*) { // [x:⊤]3: inc(); // [x:⊤]4: } // [x:⊤]5: x = 0; // [x:0+]6: x++; // [x:0+] 7: assert(x >= 0);8: x = -x; // [x:⊤]9: inc(); // [x:⊤]10: assert(x >= 0);11: }12:13: void inc() { // [x:0+] [x:⊤]14: x++; // [x:0+] [x:⊤]15: }

1) Collect all the proved approximate queries.2) For such queries, find relevant procedure calls.3) All those calls should be treated context-sensitively.

Saturday, 8 June 13

Page 99: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

0: int x = -10;1: void main() { 2: while (*) { 3: inc(); 4: } 5: x = 0; 6: x++; 7: assert(x > 0);8: x = -x; 9: inc(); 10: assert(x >= 0);11: }12:13: void inc() { 14: x++; 15: }

1) Collect all the proved approximate queries.2) For such queries, find relevant procedure calls.3) All those calls should be treated context-sensitively. 4) Run the original analysis.

Saturday, 8 June 13

Page 100: A few lessons that I learnt about interprocedural …...A few lessons that I learnt about interprocedural analyses Hongseok Yang (Univ. of Oxford) Mayur Naik, Ravi Mangal, Xin Zhang

Experimental results

Program LOC C.I.A. Partially Context-Sensitive Analysis Alarms# Time"#alarm time #alarm pre main total #selected call-sites depth

spell-1.0 2K 58 0.6 30 0.3 0.9 1.2 25 / 124 (20.2%) 1.08 (3) 48.3% 2.0⇥bc-1.06 13K 606 15.6 483 6.5 15.3 21.8 29 / 777 (3.7%) 1.16 (2) 20.3% 1.4⇥tar-1.17 20K 940 43.8 799 11.8 43.5 55.3 56 / 1213 (4.6%) 1.02 (3) 15.0% 1.3⇥less-382 24K 654 131.1 561 11.9 184.7 196.6 59 / 1522 (3.9%) 1.71 (4) 14.2% 1.5⇥make-3.76.1 27K 1500 89.3 1002 20.3 124.2 144.5 87 / 1050 (8.3%) 1.20 (2) 33.2% 1.6⇥grep-2.5 31K 1191 12.5 1182 5.8 15.4 21.2 37 / 530 (8.3%) 1.16 (3) 0.8% 1.7⇥wget-1.9 35K 1307 72.0 905 29.9 126.1 156.0 111 / 1973 (5.6%) 1.39 (5) 30.8% 2.2⇥bison-2.4 56K 2439 61.9 2249 52.6 37.5 69.93 165 / 1457(11.3%) 1.53 (4) 7.8% 1.5⇥a2ps-4.14 64K 3682 125.0 2004 205.3 343.6 548.9 263 / 2450(10.7%) 2.20 (9) 45.6% 4.4⇥lsh-2.0.4 111K 631 256.9 626 142.6 271.7 414.3 63 / 891 (7.7%) 2.96 (5) 0.8% 1.6⇥Total 385K 13008 808.7 9841 486.9 1162.9 1629.7 764 / 13558(5.6%) 24.3% 2.0⇥

Table 1. Experiemntal results: performance comparison between context-insensitive analysis (C.I.A.) and our partiallycontext-sensitive analysis. Lines of code (LOC) was obtained by running wc on the source code before preprocessing andmacro expansion. #alarm reports the number of buffer-overrun alarms raised by the analysis. pre reports the time spent by thepre-analysis and main reports the time spent by the main analysis of our approach. Each entry a/b (c%) in column #selectedcall-sites means that, among b call-sites in the program, a call-sites are selected to be context-sensitive by our pre-analysisand the selection ratio is c%. Each x (y) in column depth reports the average call-depth (x) of the call sequences that aredistinguished by our approach and the maximum call-depth (y). Alarms# reports the reduction of alarms and Time" showsthe time overhead of our method.

16 2013/3/28

We used an interval analysis for C programs.Alarms are related to potential buffer overruns.

Saturday, 8 June 13