Download Paper - STS
Transcript
3.3 Backward Data Flow Analysis to Track Predicates
{}
{}
x 6= 0 1
{}
x 6= 0 1
{}
x=12
{}
x=14
{0 ≤ x, x < 5}
{0 ≤ x, x < 5}
h=13
h=15
{0 ≤ x, x < 5}
{0 ≤ x, x < 5}
6
{}
x=12
x=14
{0 ≤ x, x < 5}
{0 ≤ x,
x < 5}
{0 ≤ x, x < 5}
h=13
h=15
{0 ≤ x, x < 5}
{0 ≤ x,
x < 5}
{0 ≤ x, x < 5}
6
{0 ≤ x, x < 5}
h = a[x] 7
{}
{0 ≤ x,
x < 5}
{0 ≤ x, x < 5}
h = a[x] 7
{0 ≤ x,
x < 5}
{}
Figure 3.16: Example with a Drawback Figure 3.17: Drawback Example with Inwhen Applying the Backward
serted Warning
Analysis
In the seventh block, we have a corresponding warning with the predicates 0 ≤ x
and x < 5 that we add to our flow data. We propagate the flow data upwards in both
branches of the if then else construct. In each branch, we encounter a block where
we reassign x. By reassigning x, we remove the predicates from the flow data.
The result of the backward analysis states that the predicates 0 ≤ x and x < 5 still
hold at the third and fifth block. However, the predicates do not hold anymore at the
second and fourth block. Therefore, we add corresponding warnings with the predicates
to the third and fifth block as shown in Figure 3.17. So, we pushed the warning from
the seventh block to the reassignments in the second and fourth block.
Even though we achieved our goal to push the warning to the last assignment, we
pushed the warning into two branches. Hence, we had to add two warning based on
one original warning. Applying the forward analysis this time, we can only remove the
warning in the seventh block. Thus, by inserting two warnings, we are able to remove one
warning. However, our goal is to reduce the number of warnings with our bidirectional
predicate propagation. In this case, we increased the number of warnings by one.
To summarise, the backward analysis can be of great help to remove even more warnings, since the warnings get pushed closer to the assignment. Having the variable closer
to the assignment might make it easier to determine if the predicate actually holds.
However, by pushing the warning into branches it can be the case that we end up with
more warnings than we originally started with.
39