Parametric Shape Analysis via 3-Valued Logic Chenguang Sun - - PowerPoint PPT Presentation

parametric shape analysis via 3 valued logic
SMART_READER_LITE
LIVE PREVIEW

Parametric Shape Analysis via 3-Valued Logic Chenguang Sun - - PowerPoint PPT Presentation

Parametric Shape Analysis via 3-Valued Logic Chenguang Sun sun47@purdue.edu Previously on Points-to Analysis Our method computes the points-to relationships between stack locations (Page 242) In the case of stack-based


slide-1
SLIDE 1

Parametric Shape Analysis via 3-Valued Logic

Chenguang Sun sun47@purdue.edu

slide-2
SLIDE 2

Previously on “Points-to” Analysis

 “Our method computes the points-to relationships between

stack locations” (Page 242)

 “In the case of stack-based aliases a name exists for each

stack location of interest.” (Page 243)

 “There are no natural names for each location (in heap)”

(Page 243)

 “We use a single location called heap in our abstract stack

for the points-to analysis.” (Page 254)

slide-3
SLIDE 3

Previously on “Points-to” Analysis

 “The stack and heap problems can and should

be separated.” (Page 254)

slide-4
SLIDE 4

Sample Program

slide-5
SLIDE 5

Representing Store via Graph

 A “store” is the memory state that arise at a

given point in the program.

 In the graph

 x: Variable  n: Field n of a node  ui: Node

u3

x

n n u1 u2

slide-6
SLIDE 6

Representing Concrete Stores via First Order Logic

 Predicates

 “pointed-to-by-variable” (Unary)  Pointers from stack into the heap  Example: x, y, t, e  “pointer-component-points-to” (Binary)  Pointer-valued fields of data

structures

 Example: n

u3

x

n n u1 u2

slide-7
SLIDE 7

Representing Concrete Stores via First Order Logic

 Logical structure S=<US, ιS>

 US: Universe of individuals

 In this example, individuals are nodes  Example: u1, u2, u3

 ιS: arity-k Predicates → (Universek → {0, 1})

 Example:

u1 1 u2 u3

x n

u1 u2 u3 u1 1 u2 1 u3 u3

x

n n u1 u2

slide-8
SLIDE 8

There are infinite structures. We need a way to abstract.

slide-9
SLIDE 9

Canonical Abstraction

 We consider unary

predicates only. Since

 x(u2) = x(u3) = x(u4)  y(u2) = y(u3) = y(u4)  t(u2) = t(u3) = t(u4)  e(u2) = e(u3) = e(u4)  u2, u3, u4 can be abstracted

as one summary node u234

slide-10
SLIDE 10

Canonical Abstraction

Merge u2 u3 u4 Merge u2 u3 u4

?

slide-11
SLIDE 11

Kleene's Three-Valued Logic

 One more logical literal ½

 0 and 1 are definite values;  ½ means “unknown” which is a indefinite value.

slide-12
SLIDE 12

Kleene's Three-Valued Logic

 l1 ⊑ l2 denotes that l1 has more definite

information than l2;

 ⊔ denotes least-upper-bound with

respect to ⊑

 ⊔{0, 1} = ½

slide-13
SLIDE 13

Kleene's Three-Valued Logic

slide-14
SLIDE 14

Canonical Abstraction

Merge u2 u3 u4

slide-15
SLIDE 15

Canonical Abstraction

 An additional unary predicate, called sm

(standing for “summary”) is added to capture whether a node is abstract.

 sm(concrete node) = 0  sm(abstract node) = ½

 sm is not an abstraction predicate 

slide-16
SLIDE 16
slide-17
SLIDE 17

The Meaning of Program Statements

 Predicate-update formula

 For every statement st, the new values of every

predicate p are defined via a predicate-update formula ( ).

φ st p

slide-18
SLIDE 18
slide-19
SLIDE 19

The Meaning of Program Statements

 Structure transformer

slide-20
SLIDE 20

Each Statement st Is A Transformer of S

 When st is not malloc()

 US unchanged  ιS(p) =

 When st is malloc()

 US = US ⋃ {unew}  ιS(p) =

φ st p φ st p

slide-21
SLIDE 21
slide-22
SLIDE 22

Is Sa acyclic?

u3

x

n n u1 u2 n u4 n

y

slide-23
SLIDE 23

Instrumentation Predicates

 Solution

 Add another predicate cn. cn(u) is 1 when there is a

path along n fields from u to u itself, otherwise 0.

 Use cn as an additional abstraction predicate.

slide-24
SLIDE 24

Instrumentation Predicates

slide-25
SLIDE 25

Predicate-Update Formula for Cn

slide-26
SLIDE 26

Other Instrumentation Predicates

slide-27
SLIDE 27

Other Instrumentation Predicates

slide-28
SLIDE 28

Predicate-Update Formula for rz,n

slide-29
SLIDE 29

Predicate-Update Formula for Instrumentation Predicates

slide-30
SLIDE 30

Instrumentation Predicates

 Speed and Accuracy

 More instrumentation-predicates;  More information (more accurate);  More abstraction nodes (slower to process);

slide-31
SLIDE 31

Improve Abstract Semantics

 New value of y becomes indefinite.

st0: y = y n →

slide-32
SLIDE 32

Impossible Structures That Could Be Represented By Sb

slide-33
SLIDE 33

The Focus Operation

φ0 is the predicate update formula for y

Partition the set of structures represented by Sa to three subset

  • f structures represented by Sa,f,0, Sa,f,1, and Sa,f,2 respectively,

where φ0 evaluates to definite values.

slide-34
SLIDE 34

Structure Transformation

 st0: y = y

n →

slide-35
SLIDE 35

Compatibility Constraints

 Constraints from the semantics of the

programming language (C language)

slide-36
SLIDE 36

Compatibility Constraints

 Constraints from the definitions of the

instrumentation predicates

slide-37
SLIDE 37

The Coerce Operation

 Sa,o,0 violates the constraint (irreparable):

slide-38
SLIDE 38

The Coerce Operation

 Sa,o,1 and Sa,o,0 violate the constraints (fixable):

slide-39
SLIDE 39

Semantic Reduction

 The Focus and Coerce convert a set of three-

valued structures into a more precise set of structures that describe the same set of stores.

slide-40
SLIDE 40

The Shape-Analysis Algorithm

 The shape-analysis algorithm itself is an

iterative procedure that computes a set of structures, StructSet[v], for each vertex v of control-flow graph G, as a least fixed point of the following system of equations.

slide-41
SLIDE 41

Convergence of The Shape-Analysis Algorithm

∣U

S∣≤2∣A∣Aisthe set of abstraction predicates

 The number of predicates is fixed.  With canonical abstraction, the number of

individuals is bounded.

 The number of possible structures is bounded.

slide-42
SLIDE 42

To Beat A Dead Horse Again

 Why we need instrument predicates?

 To collect the information we are interested in.

 Why we need Focus operations?

 To maintain the precision of these information by

making sure that the formulas that define the meaning of st evaluate to definite values.

 Why we need Coerce operations?

 To minimize the set of possible structures by

removing impossible structures.

slide-43
SLIDE 43

Thanks! Thanks! s!