interprocedural analysis
play

Interprocedural Analysis 15819M 15819M Program Analysis Jonathan - PowerPoint PPT Presentation

Interprocedural Analysis 15819M 15819M Program Analysis Jonathan Aldrich Interprocedural Analysis Strategies Make default assumptions Assume and check annotations Build Interprocedural CFG Compute Summaries


  1. Interprocedural Analysis 15�819M 15�819M Program Analysis Jonathan Aldrich

  2. Interprocedural Analysis Strategies • Make default assumptions • Assume and check annotations • Build Interprocedural CFG • • Compute Summaries Compute Summaries • All contexts one by one • Each context on demand • All context at once ���������������� ���������������������������������������� � �����������������������

  3. Making Default Assumptions • Assumptions • Starting dataflow value for all parameters • Dataflow value for result • Starting and ending information for globals if you’re tracking them ( ������������������� ) • • Verification Verification • Initial info: starting value for parameters Verify result ⊑ assumption result • • Ending value for result obeys assumption Verify arg ⊑ assumption arg • • Actual arguments obey assumptions of formal parameter • Similar extension to globals if you’re tracking them ���������������� ���������������������������������������� � �����������������������

  4. Making Default Assumptions • Example: Zero Analysis Default: ⊤ (MZ) for arguments and results • • Benefit: actual arguments and actual result always obey assumption • Cost: very conservative for arguments • Will report false positive errors • • Globals: easiest solution is not to track them Globals: easiest solution is not to track them Could also track but assume ⊤ at boundaries • ���������������� ���������������������������������������� � �����������������������

  5. Example: Default Assumptions int divByX(int x) { • Analyze divByX [result := 10/x] 1 ; p x result } 0 MZ MZ 1 MZ NZ void caller() { • Warning: div by zero at 1 [x := 5] 1 ; Verify σ [result] ⊑ MZ • [y := divByX(x)] 2 ; • • Analyze caller Analyze caller 2 } p x y 0 MZ MZ 1 NZ MZ 2 NZ MZ Verify σ [x] ⊑ MZ • • Note that div by zero can’t happen! ���������������� ���������������������������������������� � �����������������������

  6. Optimistic Assumption: NZ int divByX(int x) { • Analyze divByX [result := 10/x] 1 ; p x result } 0 NZ MZ 1 NZ NZ void caller() { • No warning [x := 5] 1 ; Verify σ [result] ⊑ NZ • [y := divByX(x)] 2 ; • • Analyze caller Analyze caller 2 } p x y 0 MZ MZ 1 NZ MZ 2 NZ NZ Verify σ [x] ⊑ NZ • ���������������� ���������������������������������������� � �����������������������

  7. Optimistic Assumption: NZ int double(int x) { • Analyze double [result := 2*x] 1 ; p x result } 0 NZ MZ 1 NZ NZ void caller() { • No warning [x := 0] 1 ; Verify σ [result] ⊑ NZ • [y := double(x)] 2 ; • • Analyze caller Analyze caller 2 } p x y 0 MZ MZ 1 Z MZ 2 Z NZ Verify σ [x] ⊑ NZ fails! • • False positive—this code is OK ���������������� ���������������������������������������� � �����������������������

  8. Assume and Check Annotations • Annotations • Starting dataflow value for all parameters • Dataflow value for result • Verification • • Initial info: starting value for parameters Initial info: starting value for parameters Verify result ⊑ annotation result • • Ending value for result obeys annotation Verify arg ⊑ annotation arg • • Actual arguments obey annotations on formal parameter ���������������� ���������������������������������������� �����������������������

  9. Assumption Example • Analyze divByX @NZ int divByX(@NZ int x) { [result := 10/x] 1 ; p x result } 0 NZ MZ 1 NZ NZ void caller() { Verify σ [result] ⊑ NZ • [x := 5] 1 ; • Analyze caller [y := divByX(x)] 2 ; 2 p p x x y y } 0 MZ MZ 1 NZ MZ 2 NZ NZ Verify σ [x] ⊑ NZ • ���������������� ���������������������������������������� ! �����������������������

  10. Assumption Example • Analyze divByX @MZ int double(@MZ int x) { [result := 2*x] 1 ; p x result } 0 MZ MZ 1 MZ MZ void caller() { Verify σ [result] ⊑ MZ • [x := 5] 1 ; • Analyze caller [y := double(x)] 2 ; 2 p p x x y y z z [z := 10/y] 3 ; } 0 MZ MZ MZ 1 NZ MZ MZ 2 NZ MZ MZ Verify σ [x] ⊑ MZ • 3 NZ MZ MZ • Warning: possible div by zero • False positive! ���������������� ���������������������������������������� �� �����������������������

  11. Interprocedural CFG Intuition BEGIN BEGIN [y:=5] 1 [result:=w*2] 1 END END [x:=double(y)] [x:=double(y)] 2 BEGIN [z:=divByX(x)] 2 [result:=10/v] 1 END END ���������������� ���������������������������������������� �� �����������������������

  12. Interprocedural CFG Intuition BEGIN BEGIN [y:=5] 1 [x:=y*2] 1 END END [x:=double(y)] [x:=double(y)] 2 BEGIN [z:=divByX(x)] 2 [z:=10/x] 1 END END ���������������� ���������������������������������������� �� �����������������������

  13. Interprocedural CFG Example int double(int x) { p x y z [y := 2*x] 6 ; 0 MZ MZ MZ } 1 NZ MZ MZ 6 NZ NZ MZ void caller() { 2 NZ NZ MZ [x := 5] 1 ; 3 NZ NZ NZ • No div by zero [y := double(x)] 2 ; 2 4 4 Z Z NZ NZ NZ NZ [z := 10/y] 3 ; 6 MZ MZ MZ [x := 0] 4 ; 5 MZ MZ MZ [y := double(x)] 5 ; • Must revisit node 2 because result } of double changed 2 MZ MZ MZ 3 MZ MZ NZ • Divide by zero warning • False positive! ���������������� ���������������������������������������� �� �����������������������

  14. Context Sensitive Summaries • Intuition • Interprocedural CFG loses too much precision when a function is called with different argument dataflow lattice elements • Simple annotations have same issue • • (but same Summary technique works there) (but same Summary technique works there) • Summaries • Maps from input dataflow information to output dataflow information • ����������������� : different results for different calls • When function is called, apply the map! ���������������� ���������������������������������������� �� �����������������������

  15. Generating Context Sensitive Summaries • Brute force • Analyze the function once for each possible input lattice element • Problem: way too many lattice elements—would take too long • On demand • • Analyze the function once for each actual input lattice Analyze the function once for each actual input lattice element it is called with • Much better—but can still be impractical for large programs with precise lattices • Abstract summaries • Symbolically represent function’s effect on input lattice element • Example: PREfix’s technique • The state of the art in interprocedural analysis ���������������� ���������������������������������������� �� �����������������������

  16. On Demand Summaries /* Summary p x y z * Case x:NZ �> result:NZ 0 MZ MZ MZ 1 NZ MZ MZ */ 2 NZ NZ MZ int double(int x) { [result := 2*x] 1 ; Compute summary of double for x:NZ } p x result 0 NZ MZ void caller() { 1 NZ NZ [x := 5] 1 ; [y := double(x)] 2 ; [z := 10/y] 3 ; [x := 0] 4 ; [y := double(x)] 5 ; } ���������������� ���������������������������������������� �� �����������������������

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend