Docsity

The Tool Based on the Data Flow Analysis | CMSC 631, Assignments of Computer Science

Toggle sidebar
bg1
Tools Based on Data Flow Analysis
CMSC 631 – Program Analysis and
Understanding
Fall 2003
2
CMSC 631, Fall 2003
• Office hour change:
ā– TuTh 10-11, or by appointment
ā– (Friday office hour conflicted with SysChat)
ā– 
• Typo on HW1 fixed
ā– Ignore ā€œinduction variablesā€ part
ā– Copy statement is of form x := y
ā– 
• Papers for next time
ā– Don’t get caught up in unfamiliar terms in survey
ā– Second ā€œpaperā€ is really for marketing purposes
Administrivia
3
CMSC 631, Fall 2003
• Too hard/easy?
• Amount of reading?
• Background assumptions?
Class So Far
4
CMSC 631, Fall 2003
•Interprocedural
ā– Multiple procedures at a time
•Intraprocedural
ā– One procedure at a time
Terminology
5
CMSC 631, Fall 2003
• All program analyses must be approximate
ā– see paper for Thursday
• A program checking system is sound if
ā– Every dynamic error that could occur is detected
ā– But the static checking system may complain about
things that can’t actually happen
• A program checking system is complete if
ā– Everything that is detected is an actual error
ā– But some actual errors may not be caught
Sound and Complete
6
CMSC 631, Fall 2003
• Is LCLint
ā– Inter- or intraprocedural?
ā– Sound? Complete?
• Is ESP
ā– Inter- or intraprocedural?
ā– Sound? Complete?
The Tools
pf3
pf4
pf5

Partial preview of the text

Download The Tool Based on the Data Flow Analysis | CMSC 631 and more Assignments Computer Science in PDF only on Docsity!

Tools Based on Data Flow Analysis

CMSC 631 – Pr Under Faoll 2003gsrtaamnding Analysis and

CMSC 631, Fall 2003 2

• Offi ā–  Tuce hour change:Th 10-11, or by appointment

• T^ ā– ^ ā– ^ y(Fridapo on HW1 fiy^ office hour conflxed icted with SysChat)

ā–  ā–  IgnorCopye statement is of f ā€œinduction variablesā€ parorm x := yt

• Pa^ ā– pers for next time

ā–  ā–  Don’Secondt get caught up in unfamiliar terms in sur ā€œpaperā€ is really for marketing purposesvey

Administrivia

CMSC 631, Fall 2003 3

• Too hard/easy?

• Amount of reading?

• Background assumptions?

Class So Far

CMSC 631, Fall 2003 4

• Inter ā–  Multiple prproceduralocedures at a time

• Intr ā–  One pr a proceduralocedure at a time

Terminology

• All pr ā–  see paogram analper for Thursdayses my ust be approximate

• A pr ā–  Eveorgram checking system isy dynamic error that could occur is detected sound if

ā–  But the static checking system ma things that can’t actually happen y complain about

• A pr ā–  Eveorgram checking system isything that is detected is an actual er complete ro rif

ā–  But some actual errors may not be caught

Sound and Complete

• Is LCLint ā–  Inter- or intraprocedural?

ā–  (^) Sound? Complete?

• Is ESP ā–  Inter- or intraprocedural?

ā–  Sound? Complete?

The Tools

CMSC 631, Fall 2003 7

• So what? ā–  At least we know what we’re sound up to

ā–  It’ - sPr not anoof: Wyrite a C interpr better in theoreter in Jay in other languagesva

No (Usef char *s, *t; ul) Tool for C is Sound

intptr_t i, j=0; j; f t = (char *) j;or (i =0; i<s; i++) j++;

CMSC 631, Fall 2003 8

• What ar static anale ythe tradeoffs betwsis? een testing and

•^ ā– ^ Other techniques for detecting errors?

• What does it mean f ā–  ā–  Annotations?Redundancy or a program to be correct?

Big Questions

CMSC 631, Fall 2003 9

• Is the anal ā–  Full vs parytsis scalable?ial correctness

• What kinds of annotations ar ā–  Will programmers actually use them?e necessary?

• What pr ā–  How flexible aroblems can be solve the tools? ed?

Questions About the Tools

CMSC 631, Fall 2003 10

• T ā– r ies to detect thrNull pointer derefeere classes of erences rors:

ā–  ā–  (^) Uninitialized memorAllocation/deallocation pry oblems ā–  (^) (Plus more stuff not in this paper)

• Technique: Data flow analysis

LCLint

• Thr ā–  nuell = mae ā€œnullnessā€ states possible:y be NULL

ā–  ā–  (^) notnrelnuull = don’ll = defitnitel carye not NULL

• Example fr extern char gname; void setName(/@nom paull@*/ char *pname) {per:

}^ gname = pname;

Null Pointer Errors

• Annotations ā–  Syntax?

ā–  ā–  (^) Location? (with code/someDefault assumptions? where else)

• How do we merge states?

Discussion

CMSC 631, Fall 2003 19

• What ha ā–  Examples frppens if wom Das’es MIT talkdon’t track predicates?

Standard Data Flow

e dnumtryp Open P x := (^0) dump x := 1 Close exit

T F T F T F

Closed Closed, Open Closed, Open Closed, Open, Error CMSC 631, Fall 2003 20

• Standar all paths solutiond data flow analysis computes meet over

• An anal different infysis isormation on diff path sensitive if wereent paths compute

ā–  ā–  PrAlloedicates at branches along each path arws you to track correlated branchese modeled

• P ā– o Scalability?tential downside:

Path Sensitivity

CMSC 631, Fall 2003 21

• Here are two paths (how many possible?)

Example Revisited

e dnumtryp Open P x := (^0) dump x := 1 Close exit

T F T F T F

Closed,^ Closed dump=T Open,^ Open, dump=T^ dump=T, P=T Open, Open, dump=Tdump=T,, P=T P=T,, x=0x= Closed, dump=T, P=T, x=

Open,^ Open, dump=T^ dump=T, P=F,^ P=F, x= Closed,^ Open,^ dump=T dump=T,^ ,P=F P=F,^ ,x=1 x= CMSC 631, Fall 2003 22

• Split data fl ā–  (abstract stateow ,fact into tw execution state)o parts

    • abstract state = state in automatonexecution state = predicates along path ā–  (^) Meaning, corresponds to abstract state if predicates along path are true, then state ā–  (^) Data flow fact is a set (i.e., conjunction) of these

• A branch is ir care about, both branches arrelevant if, for the pre in the sameoperty we

abstract state

K Preey Idea: Tdicates rack Only Some

• With ESP, paths with dump = true

Example Revisited, Again

e dnumtryp Open P x := (^0) dump x := 1 Close exit

T F T F T F

Closed,^ Closed dump=T Open,^ Open, dump=T^ dump=T, P=T Open, Open, dump=T dump=T, P=T, x= Closed, dump=T

Open,^ Open, dump=T^ dump=T, P=F,^ P=F, x=

• Full path sensitivity: Don’t merge any facts

• Standard data flow: One fact at join, take lub

• ESP: One fact per abstract state at join

Merge Functions at Join

αcs (ss) = ss αdf (ss) = {( (^) sā‹ƒāˆˆss as(s), (^) sāŠ”āˆˆss es(s))} αas (ss) = {({d}, (^) sāˆˆāŠ”ss[d] es(e))|d ∈ D ∧ ss[d] #= āˆ…}

CMSC 631, Fall 2003 25

• Pr diffoeblem:rent objects whose state w Big programs may contain mane want to tracky

ā–  Multiple automata per pr explosion, again ogram point = state space

• Solution: ā–  But then ho Onlwy do w model one automaton at a timee know which statements change

the state of the automaton?

Scaling to Large Programs

CMSC 631, Fall 2003 26

• P ā– e Determines which exprrform initial may alias analessions in prysis ogram may refer

to same object (may alias)

• At statement that transitions automaton ā–  E.g., fclose(e)

ā–  ā–  (^) If e maIf e mayy alias the object walso alias something elsee’re tracking,, then transition ma do transitiony not ha - Assume might also not happen ve taken transition

Alias Analysis

CMSC 631, Fall 2003 27

• • Cuts doCuts dowwn on state spacen on relevant branches

• May be amenable to parallel execution

• But...can’t model correlations between automata

Consequences

CMSC 631, Fall 2003 28

• Anal ā–  Multiple calls to same function trysis is context-sensitive eated separately

ā–  (^) ...almost

• When call a function in some (abstract state execution state) ,

ā–  (^) If w model the function in that abstract statee’ve never called function in that abstract state, ā–  ā–  (^) OtherwiseIgnore execution state, reuse previous results

Function Calls

• Fr ā–  ogcc 2.5.3 (spec 95)m Das’s MIT talk

• When gcc prints to a fi always open? le (fprintf), is the file

• Stats: ā–  140K non-blank, non-comment lines of C

ā–  2149 functions, 66 files, 1086 globals

Case Study: Files in gcc

State State State State UninitClosedOpenedError Initial Initial Event Print EventEvent {ASTFUNCTIONCALL DeclOpen {ASTDECLARATION{ {object {ASTSYMBOL_object_ ASTFUNCTIONCALLASTSYMBOL ā€œfopenā€} any}}{anyargs}} Event Transition Close _{ASTFUNCTIONCALL {ASTSYMBOL {ASTSYMBOL-> Uninit onā€œfprintfā€}ā€œfcloseā€} Decl {{object__object}},anyargs}} Transition Transition Transition Transition Transition _UninitOpenedClosedOpened -> Opened ->->->-> ErrorOpenedErrorClosed on Open on (^) on onon Print (^) Print PrintClose ā€œFileā€œPrinting not openedā€to closed fileā€ Transition Closed -> Error on Close ā€œFile already closedā€

Automaton Specification