A variable x is said to be live at a statement si in a program if the…
2015
A variable x is said to be live at a statement si in a program if the following three conditions hold simultaneously:
There exists a statement sj that uses x
There is a path from si to sj in the flow graph corresponding to the program
The path has no intervening assignment to x including at si and sj

The variables which are live both at the statement in basic block 2 and at the statement in basic block 3 of the above control flow graph are
- A.
p, s, u
- B.
r, s, u
- C.
r, u
- D.
q, v
Attempted by 22 students.
Show answer & explanation
Correct answer: C
Live variable analysis tracks variables used before redefinition. In Block 2, v = r + u uses r and u, making them live at the entry of Block 2. In Block 3, q = s * u uses s and u. Additionally, paths from Block 3 lead to Block 4 where v and r are used, so they remain live at the entry of Block 3. Comparing the sets {r, u} for Block 2 and {s, u, v, r} for Block 3 reveals the common live variables are r and u.
A video solution is available for this question — log in and enroll to watch it.