Control flow graph dominance

176 views Asked by At

I am studying compilers for a personal project and to do that I was looking at some papers from a university in the UK. One of the questions I stumbled upon reads as follows:

Draw a CFG which contains a definition followed by a use of a variable x, but in 
which the use of x is not dominated by any definitions of x.

How is this possible? If the use is not dominated by a definition, that means the block where x is used would have x out of scope? Am I not looking at it correctly?

Say we have

1: int y = 2;

2: if (y > 0)

3: int x = 5;

4: else x++;

In this case, the use of x is not dominated by the definition, but x is not in scope so it can't be used. I don't get it...

1

There are 1 answers

0
TehMillhouse On

Keep in mind that the definition of x and its declaration are two different things, and scoping only cares about declarations. Consider the following:

int x;
if (user_input_integer() == 0) {
    x = 0;
} else {
    x = 1;
}
x++;