static1 - Introduction A Tiny Example Language Type...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Introduction Introduction A Tiny Example Language A Tiny Example Language Type Analysis Type Analysis Static Analysis 2009 Static Analysis 2009 Michael I. Schwartzbach Computer Science, University of Aarhus
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 2 Static Analysis Questions About Programs Questions About Programs ± Does the program terminate? ± How large can the heap become during execution? ± What is the possible output?
Background image of page 2
3 3 Static Analysis Program Points Program Points foo(p,x) { var f,q; if (*p==0) { f=1; } else { q = malloc; *q = (*p)-1; f=(*p)*((x)(q,x)); } return f; } ± A property holds at a program point if it holds in any such state for any execution with any input any point in the program = any value of the PC
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 4 Static Analysis Questions About Program Points Questions About Program Points ± Will the value of x be read in the future? ± Can the pointer p be null ? ± Which variables can p point to? ± Is the variable x initialized before it is read? ± What is a lower and upper bound on the value of the integer variable x ? ± At which program points could x be assigned its current value? ± Do p and q point to disjoint structures in the heap?
Background image of page 4
5 5 Static Analysis Why Are The Answers Interesting? Why Are The Answers Interesting? ± Ensure correctness: • verify behavior • catch bugs early ± Increase efficiency: • resource usage • compiler optimizations
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 6 Static Analysis Rice Rice s Theorem, 1953 s Theorem, 1953
Background image of page 6
7 7 Static Analysis Rice Rice s Theorem s Theorem Any non-trivial property of the behavior of programs in a Turing-complete language is undecidable!
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 8 Static Analysis Easy Reduction Easy Reduction ± Can we decide if a variable has a constant value? x = 17; if (TM( j )) x = 18; ± Here, x is constant if and only if the j ’th Turing machine halts on empty input.
Background image of page 8
9 9 Static Analysis Approximation Approximation ± Approximate answers may be decidable! ± The approximation must be conservative : •e i t h e r yes ”or” no ” must always be the correct answer • which direction depends on the client application • the useful answer must always be correct ± More subtle approximations if not only ” yes ”/” no
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10 10 Static Analysis Example Approximations Example Approximations ± Decide if a function is ever called at runtime: •i f no ”, remove the function from the code f yes ”, don’t do anything • the ” no ”answer must always be correct if given ± Decide if a cast (A)x will always succeed: f yes ”, don’t generate a runtime check f no ”, generate code for the cast • the ” yes ” answer must always be correct if given
Background image of page 10
11 11 Static Analysis Beyond Beyond Yes Yes / / No No Problems Problems ± Which variables may be the targets of a pointer variable p ? ± If we want to replace *p by x : • answer &x if x is guaranteed to be the only target • answer ? otherwise ± If we want to know the maximal size of *p : • answer { &x , &y , &z , . ..} • guaranteed to contain all targets (but may be too large)
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
12 12 Static Analysis The Engineering Challenge The Engineering Challenge ±
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/18/2011 for the course COMPUTER 091 taught by Professor Rajivsir during the Spring '11 term at MIT.

Page1 / 60

static1 - Introduction A Tiny Example Language Type...

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online