GATE Computer ScienceHardGATE CS (PYQ pattern)

In 1: x = 1; 2: y = 0; 3: L1: if y > n goto L3; 4: if x > 5 goto L2; 5: x = x * 2; 6: L2: y = y + x; 7: x = y - 1; 8: if y < m goto L1; 9: x = 0; 10: L3: return x, which definitions of x (named by statement number) reach statement 6 (L2), and which reach statement 10 (L3)?

  1. A. {1, 5, 7} at 6; {1, 7, 9} at 10
  2. B. {1, 5, 7} at 6; {7, 9} at 10
  3. C. {5, 7} at 6; {1, 7, 9} at 10
  4. D. {1, 5, 7} at 6; {1, 5, 7, 9} at 10

Correct answer: A. {1, 5, 7} at 6; {1, 7, 9} at 10

x is defined at 1, 5, 7 and 9. At L1 the definitions 1 (first entry) and 7 (back edge from 8) arrive. Statement 6 is reached from 4 (carrying 1 and 7) and from 5: {1, 5, 7}. L3 is reached from the test at 3 (carrying 1 and 7; 5 is always killed by 7 before the back edge) and from 9: {1, 7, 9}.

More Compiler Design questions

Exams that ask this topic