Topic 5 · Class activity 5 · Week 14 · Wednesday

Audit Somebody Else's Compiler

Five adversarial programs each, rotate, diagnose by phase, fix one bug before you leave.

Format groups of threeTime 50 minBring a compiler you believe works

The point

Audit somebody else's compiler adversarially. The Topic 5 objective is literally audit the correctness of the AST and semantic actions of the parser — this is that, done to each other.

How to run it

  1. Everyone writes five adversarial programs — designed to break a compiler that was tested casually. Starting points:
    • an if with an empty body, or a bare block as its body
    • if inside a loop inside an if
    • a break inside a switch inside a loop
    • a switch whose controlling expression is a function call
    • a case body containing a return
    • if (a) if (b) X else Y with all four truth combinations
    • a switch with no default and no matching case
    • 2 && 1, and !5
  2. Write the expected output for each, by hand, before running anything.
  3. Rotate. Run your five on both other compilers and record every disagreement.
  4. Diagnose by phase. For each failure, find the phase responsible. The AST dump is the fastest tool: if the tree is wrong, nothing downstream can be right, and the search is narrowed to two files.
  5. Fix one bug each, in your own compiler, before the session ends.
The one that catches almost everyone

A return inside a switch case. If the return does not jump to the function epilogue, control falls through into the next case body and the function returns whatever the last case says. It is invisible until somebody writes exactly that program — which is the point of an adversarial session.

Deliverable

Your five programs with expected outputs; a table of which compilers failed which tests; and a one-paragraph diagnosis of the bug you fixed, naming the phase and the line.