[CST-2] Optimising compilers 97 P8 Q7
lxl20@cam.ac.uk
lxl20@cam.ac.uk
Sun, 03 Jun 2001 14:08:07 +0100
Hi, I asked my supervisor a question, he kindly explained it and I thought
I'd post it here in case it's of help to anyone else.
cheers, lucy
--On Sunday, June 03, 2001, 11:14 AM +0100 Lucy Lian
<lxl20@hermes.cam.ac.uk> wrote:
> Hi Tim,
>
> I was wondering whether you know how to write the program they asked for
> in the very last part of 97 P8 Q7?
>
> I don't quite know how to do it because I think if m is an element in the
> set RD(n), then m reaches n. But how can we write a program in which no
> run-time execution causes m to reach n?
>
> Many thanks!
> Lucy
--On Sunday, June 03, 2001, 12:51 PM +0100 Tim Harris
<Tim.Harris@cl.cam.ac.uk> wrote:
> Hi -- the example for the last part of 97 P8 Q7 relies on having a
> program in which there is some path through the code such that
> an expression "m" reaches node "n", but for which no actual run
> of the program could ever cause that path to be taken.
>
> A good example is
>
> 0: <initialize x and y>
> 1: if (x == y) {
> 2: z = 12;
> 3: } else {
> 4: z = 42;
> 5: }
> 6: System.out.println (z);
>
> Here RD(6) will include {2, 4} because either the "then" part of the
> "if" statement may initialize "z" at 2, or the "else" part may initialize
> "z" at 4.
>
> However, if the code at line 0 initializes "x" and "y" so that
> they are always equal or always not equal then the same branch of the
> "if" statement will always be taken and only one of the assignments
> to "z" will ever reach line 6.
>
> Hope this helps,
>
> Tim
>
>