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