Selecting, Refining, and Evaluating Predicates for Program Analysis

Selecting, Refining, and Evaluating Predicates for Program Analysis

Selecting, Refining, and Evaluating Predicates for Program Analysis Nii Dodoo Lee Lin Michael D. Ernst Technical Report MIT-LCS-TR-914 July 21, 2003 MIT Lab for Computer Science 200 Technology Square Cambridge, MA 02139 USA fdodoo,leelin,[email protected] Abstract implementation and experimental evaluation are for a spe- cific dynamic program analysis that, given program execu- This research proposes and evaluates techniques for se- tions, produces likely invariants as output. The base analy- lecting predicates for conditional program properties — that sis reports properties such as preconditions, postconditions, is, implications such as p ) q whose consequent must be and object invariants that are unconditionally true over a test true whenever the predicate is true. Conditional properties suite. (Section 2.3 describes the technique.) are prevalent in recursive data structures, which behave dif- ferently in their base and recursive cases, in programs that A conditional property is one whose consequent is contain branches, in programs that fail only on some inputs, not universally true, but is true when the predicate is and in many other situations. The experimental context of true. (Equivalently, the consequent is false only when the research is dynamic detection of likely program invari- the predicate is false.) For instance, the local invariant ants, but the ideas are applicable to other domains. over a node n of a sorted binary tree, (n:left:value · Trying every possible predicate for conditional proper- n:value) ^ (n:right:value ¸ n:value), is true unless one ties is computationally infeasible and yields too many un- of n, n.left, or n.right is null. Conditional properties are desirable properties. This paper compares four policies for particularly important in recursive data structures, where selecting predicates: procedure return analysis, code con- different properties typically hold in the base case and the ditionals, clustering, and random selection. It also shows recursive case. The predicates are also useful in other do- how to improve predicates via iterated analysis. An experi- mains. For instance, it can be challenging to select predi- mental evaluation demonstrates that the techniques improve cates for predicate abstraction [BMMR01]. A related con- performance on two tasks: statically proving the absence of text is determining whether to discard information at join run-time errors with a theorem-prover, and separating faulty points in an abstract interpretation such as a dataflow anal- from correct executions of erroneous programs. ysis. Extending an analysis to check implications is trivial. However, it is infeasible for a dynamic analysis to check 1 Introduction a ) b for all properties a and b that the base analysis can The goal of program analysis is to determine facts about produce. One reason is runtime cost: the change squares a program. The facts are presented to a user, depended on the number of potential properties that must be checked. A by a transformation, or used to aid another analysis. The more serious objection concerns output accuracy. Checking properties frequently take the form of logical formulae that (say) 100 times as many properties is likely to increase the are true at a particular program point or points. number of false positives by a factor of 100. This is accept- The usefulness of a program analysis depends on what able only if the number of true positives is also increased properties it can report. A major challenge is increasing the by a factor of 100, which is unlikely. False positives in- grammar of a program analysis without making the analy- clude properties that are true over the inputs but are not true sis unreasonably more expensive and without degrading the in general. In the context of interaction with humans, false quality of the output, when measured by human or machine positives also include true properties that are not useful for users of the output. the user’s current task. This paper investigates techniques for expanding the out- Since it is infeasible to check a ) b for every a and put grammar of a program analysis to include implications b, the program analysis must restrict the implications that of the form a ) b. Disjunctions such as a _ b are a spe- it checks. We propose to do so by restricting what proper- cial case of implications, since (a ) b) ´ (:a _ b). Our ties are used for the predicate a, while permitting b to range 1 over all properties reportable by the analysis. We use split- x=-9, y=3 ting conditions to partition the data under analysis, and then x= 2, y=4 combine separate analysis results to create implications or x= 0, y=1 conditional properties. Splitting conditions limit the predi- x=-1, y=.5 cates that are considered, but predicates that are not splitting x=-7, y=8 conditions may still appear. We also present a technique that x= 4, y=16 leverages the base analysis to refine imprecise predicates via ? 1. Split the data into parts ´´QQ an iterated analysis. yes ´ Q no Qx even?´ This paper presents four policies (detailed in Section 3) QQ´´ for selecting predicates for implications: procedure return ? ? analysis; code conditionals; clustering; and random selec- x=2, y=4 x=-9, y=3 x=0, y=1 x=-1, y=.5 tion. The last two, which performed best in our experimen- x=4, y=16 x=-7, y=8 tal evaluation, are dynamic analyses that examine program executions rather than program text; the second one is static; x even x odd 2. Compute properties x ¸ 0 x < 0 and the first is a hybrid. Dynamic analyses can produce in- over each subset of data y = 2x y > 0 formation (predicates) about program behavior that is not y > 0 x even , x ¸ 0 apparent from the program text — for instance, general alias 3. Compare results, x even ) y = 2x analysis remains beyond the state of the art, but runtime be- produce implications x ¸ 0 ) y = 2x havior is easy to observe. Also, the internal structure of the source code does not effect the dynamic policies. It also Figure 1. Mechanism for creation of implications. In the figure, enables them to work on programs for which source code the analysis is a dynamic one that operates over program traces. is not available, so long as the underlying program analysis Figure 2 gives the details of the third step. does not require source code. We evaluated the four policies in two different ways. // S1 and S2 are sets of properties resulting from First, we compared the accuracy of the produced proper- // analysis of partitions of the data. ties, where accuracy is measured by a program verification procedure CREATE-IMPLICATIONS(S1, S2) task (Section 4.1); the policies produced implications that for all p1 2 S1 do reduced human effort by 40%. Second, we determined how if 9p2 2 S2 such that p1 ):p2 and p2 ):p1 then well each of the policy choices exposes errors (Section 4.2); // p1 and p2 are mutually exclusive 0 12% of the implications directly reflected differences due to for all p 2 (S1 ¡ S2 ¡ fp1g) do 0 faulty behavior, even without foreknowledge of the faults. output “p1 ) p ” The remainder of this paper is organized as follows. Sec- tion 2 proposes mechanisms for detecting and refining im- Figure 2. Pseudocode for creation of implications from properties plications. Section 3 describes the four policies that deter- over partitions of the data. (In our experiments, the underlying mine which implications will be computed, and Section 4 data is be partitioned into two sets of executions; other analyses might partition paths or other code artifacts.) Figure 3 shows an evaluates them. Section 5 discusses related work, and Sec- example of the procedure’s input and output. tion 6 recaps our contributions. 2 Detecting implications If the splitting condition is poorly chosen, or if no implica- tions hold over the data, then the same properties are com- Figure 1 shows the mechanism for creation of implica- puted over each subset of the data, and no implications are tions. Rather than directly testing specific a ) b invariants, reported. the analysis splits the input data into two mutually exhaus- Figure 2 gives pseudocode for creation of implications tive parts based on a client-supplied predicate, which we from properties over subsets of the data, which is the third call a splitting condition. The splitting conditions are not step of Figure 1. The CREATE-IMPLICATIONS routine is necessarily the same as the implication predicates (see Sec- run twice, swapping the arguments, and then the results are tion 2.1). This paper focuses on automating the selection of simplified according to the rules of Boolean logic. Figures 1 splitting conditions, which are analogous to the predicates and 3 give concrete examples of the algorithm’s behavior. of predicate abstraction. Each mutually exclusive property implies everything After the data is split into two parts, the base program else true for its own subset of the data. (This is true only analysis is performed to detect (non-implication) properties because the two subsets are mutually exhaustive. For in- in each subset of the data. Finally, implications are gener- stance, given a mechanism that generates three data sub- ated from the separately-computed properties, if possible. sets inducing property sets fa; bg, f:a; :bg, fa; :bg, it is 2 Properties Implications Simplified Augmented Splitting Input data input data Properties conditions Splitting Program Extract policy analysis rhs S1 S2 a ) b :a ):b a , b Initial a :a a ) d :a ) f a ) d splits b :b a ) e :b ):a a ) e c c b ) a :b ) f :a ) f Figure 4.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    12 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us