3. Static Analysis: Overview
● Static
– Performed at compile time, i.e., without executing the program
● Analysis
– Determination of interesting properties of the run-time behavior of the
program
● The goal is to
– Enable optimizations
– Find bugs, test, debug, ....
4. Static Analysis: Motivation ─
Optimization
The optimization:
x = 1 y = 1
y = x
is unsound if x is used in a later instruction:
x = 1
y = x y = 1
... ...
z = x z = x
5. Static Analysis: Motivation ─
Checking for Unreachable Code
def foo(x: Int): Int = { def bar(b: Boolean) {
return x if (b) { return }
x = x + 1 else { return }
x = x – 1 return
} }
We’d like to notify users about the above “ill-
formed” code.
6. Static Analysis: Motivation ─
Checking for Unused Vars.
def foo() = {
val x = 0
val y = 1
bar(y)
}
We’d like to notify users about the above
ill-formed code
7. Where to Perform Analysis?
● Static analysis may take place:
– at the source code level;
– at some intermediate level; or
– at the machine code level.
●
Static analysis may look at:
– basic blocks only;
– an entire function (intraprocedural); or
– the whole program (interprocedural).
●
The precision and cost of an analysis rises as we include more
information.
8. Advantages
● Makes Programs more efficient in terms of both,
Memory & Time.
● Increases the quality & reliability of code.
● Reduces the time spent by developers in tedious jobs
like regression testing, debugging, etc.
● Helps in developing platform independent S/Ws.
9. Disadvantages
● Extra effort has to be put to Static Analyzers for a
particular S/W.
● Increases the cost of development.
● Different tools for different languages and platforms.
– Eg :- Soot (for JVM based static code analysis only)
10. Live Demo
To run this Demo, follow these steps: -
1. Install Soot by following steps given on website
http://www.sable.mcgill.ca/soot/eclipse/updates/
2. Import Soot Libraries in your project by configuring Build Path
3. Download this project from :-
https://github.com/gupta-himanshu/static-analysis-scala
4. Run it as Java Application