$ Chapter 1 — Program Analysis
Chapter 1 — Program Analysis
17 April 2021

1.3 Concepts in Program Analysis

1.3.2 Static versus Dynamic

Motivations for static analysis

1.3.3 A Hard Limit: Uncomputability

Theorem: Halting problem
The halting problem consists in finding an algorithm halt such that,
for every program p ∈ 𝙻, halt(p) = true if and only if p terminates

Theorem: Rice theorem
Let 𝙻 be a Turing-complete language, and let 𝒫 be a nontrivial semantic property of programs of 𝙻. There exists no algorithm such that,
for every program p ∈ 𝙻, it returns true if and only if p satisfies the semantic property 𝒫.

So how to design a program analysis ?

1.3.5 Approximation: Soundness and Completeness

Let analysis to be an analysis tool to determine whether this property holds:

for every program p ∈ 𝙻, analysis(p) = truep satisfies 𝒫.
can be decomposed into a pair of implications:
for every program p ∈ 𝙻, analysis(p) = truep satisfies 𝒫.
for every program p ∈ 𝙻, analysis(p) = truep satisfies 𝒫.

Soundness

A sound program analysis satisfies the first implication.

Definition: Soundness
The program analyzer analysis is sound with respect to property 𝒫 whenever, for any program p ∈ 𝙻, analysis(p) = true implies that p satisfies property 𝒫.

A sound analysis will reject all programs that do not satisfy 𝒫.

Example: Strong Typing
  • good: well-typed programs will not present certain classes of errors

  • bad: certain programs that will never crash may still be rejected

The soundness is easy to meet; we can simply reject any program. Therefore, in practice, the design of a sound analysis will try to give a conclusive answer as often as possible.

Completeness

Definition: Completeness
The program analyzer analysis is complete with respect to property 𝒫 whenever, for every program p ∈ 𝙻, such that p satisfies 𝒫, analysis(p) = true.

The completeness is also easy to meet; we can simply never reject any program. To be useful, a complete analyzer should often reject programs that don't satisfy the property of interest.

Soundness vs. Completeness

soundness-vs-completeness

Soundness vs. Completeness (adapted from Figure 1.2 from the book)

When a program analysis is automatic, it is either unsound or incomplete.

1.4 Families of Program Analysis Techniques

automatic

soundness

completeness

object

when

testing

No

No

Yes

Program

Dynamic

Assisted Proof

No

Yes

Yes/No

Model

Static

Model Checking of finite-state model

Yes

Yes

Yes

Finite Model

Static

Model Checking at program level

Yes

Yes

No

Program

Static

Conservative Static Analysis

Yes

Yes

No

Program

Static

bug finding

Yes

No

No

Program

Static

an overview of program analysis techniques