Formal methods where they pay: TLA+, model checking and proofs
A test samples the runs you can afford. A model checker visits every run of a small model. A proof covers every run of a rule. Each costs more than the one before, and each pays only in the right place
Magda models two buyers reserving the last unit of stock. Each buyer takes two steps: first it reads the count, then it writes the count minus one. The steps of different buyers can interleave in any order, which makes six orderings in all. In how many of the six does the last unit sell twice?
You met this race twice already. The chapter on testing time, randomness and concurrency lined real threads up with a barrier and repeated the round hundreds of times until a doubled order showed. The chapter on testing across services took the scheduler away from the operating system and gave it to a seeded generator, so that a failing run became a number you could replay. Both of those find bugs by running the code. Both report what they saw. Neither can say that a bug is not there. This chapter takes the last step on that ladder: write the design as a small model and let a program try every behaviour the model allows.
From sampling to exhaustive search
Every technique so far samples. An example test picks one input. A property test picks a few hundred. A simulation picks a few hundred seeds. Each sample is a world, and the bug lives in only some of the worlds. When the failing worlds are common, sampling finds them in seconds. When they need a rare sequence, sampling can run for months and say nothing.
Model checking removes the sampling. You describe the system as a set of states and a set of steps that move from one state to the next. You state an invariant, a fact that must be true in every state. The checker starts at the initial state, applies every step that is allowed, and records each new state it reaches, until nothing new appears. If any state breaks the invariant, it stops and gives you the path that led there. If none does, then no behaviour of the model breaks the invariant.
The lab has a 42-line checker in models/checker.py that does exactly this. It is a breadth-first search: a queue of states to visit and a dictionary that remembers, for each state, the one it came from. Two properties follow from that shape and are worth knowing.
- A pass is exhaustive, within the bounds. The checker visits each reachable state once. If the invariant held in all of them, no schedule of the modelled steps can break it. The bounds are the model’s own: how many buyers, how much stock, which faults you allowed.
- A failure is the shortest trace. Breadth-first search reaches every state by the fewest steps first, so the counterexample comes back as short as it can be. Hypothesis does a similar job by shrinking, but it shrinks a lucky sample. The checker never needs luck.
The reserve-stock model
The model for Ojaline’s stock race lives in models/reserve_stock.py. A state is a tuple: the stock on the shelf, the number of units sold, and what each of two buyers is doing. A buyer is idle, has read a count, or is done. A step is one buyer doing one thing. There are two versions of the step function.
- Atomic. One step: if the stock is at least 1, take the unit. This is the shape of
Database.take_stock, oneUPDATE ... WHERE on_hand >= ?, where the check and the write cannot be separated. - Racy. Two steps: first read the count, then write the count minus one. This is a check-then-act sequence. Nothing stops the other buyer from running between the two steps.
The invariant is that stock never goes below zero and no more units are sold than existed. You run both with .venv/bin/python -m models.reserve_stock. The atomic version visits 4 states and holds. The racy version breaks in five lines: A reads the count, B reads the count, A writes 0, B writes 0, and sold is 2. That trace is the one the predict question counted, and it is the same interleaving the lab’s concurrency chapters made with threads. You did not need a barrier, a loop or luck. The checker did not run the code at all. It ran the model of the code, and the model is the whole point of the technique, for good and for ill.
// Follower: apply replication messages in arrival order
function onRepl(msg) {
this.x = msg.v; // an older message arriving late overwrites a newer one
}
// Test scheduler: the real network and the OS pick the order
// (so the bad order may appear once in thousands of runs)// Follower: ignore anything older than what it already has
function onRepl(msg) {
if (msg.seq > this.seq) { this.x = msg.v; this.seq = msg.seq; }
}
// Simulator: one seeded PRNG chooses the next event
const rng = makeRng(seed);
while (queue.length) run(queue.splice(pick(queue, rng), 1)[0]);
// same seed -> same trace, every time, on every machine Look back at the simulation. It explores worlds by seed, so you see some seeds hit the bug and some miss. A model checker is what you get if you replace the seed with a loop over every choice at every step. That is why it works on small models and does not work on a real service: the simulation can run a 300-line place_order against a real database, and the checker can only run something small enough to enumerate.
Growth, and why models stay small
How small? The lab’s models/scale.py (you write it in the lab) takes any number of buyers. For one unit of stock the number of states each version visits is:
| Buyers | Atomic | Racy | With compare-and-set |
|---|---|---|---|
| 2 | 4 | 12 | 11 |
| 3 | 8 | 56 | 45 |
| 4 | 16 | 272 | 191 |
| 5 | 32 | 1,312 | 813 |
| 6 | 64 | 6,208 | 3,431 |
| 7 | 128 | 28,800 | 14,325 |
The atomic model doubles with each buyer, because each buyer is either still waiting or done. The racy model multiplies by about 4.6 to 4.9 at each step, because each buyer now has a middle state and the buyers interleave. This is the state explosion. At 7 buyers the Python checker still finishes in under a second. A model with a dozen fields per process, a network that can lose, duplicate and reorder messages, and a crash step that can happen anywhere will reach billions of states with a handful of processes.
Two habits keep it manageable, and both are craft, not theory.
Pick the smallest constants that can show the bug. The race needs two buyers and one unit. Seven buyers add 28,788 more states and no new kind of bug. Checking a small instance and trusting that a design bug that exists at all shows up in a small instance is general practice, sometimes called the small scope hypothesis. It is a hypothesis. It holds often enough to be useful, and it can fail when a bug needs a specific number of nodes or a specific length of history.
Leave out what the invariant does not touch. The model does not know about prices, VAT, cart lines or the provider. Those have no effect on whether two buyers can take one unit. A model earns its keep by being far smaller than the code, so that you can see all of it and the checker can walk all of it.
The invariant is the other half of the model
The checker cannot tell you that your invariant is right. It checks the one you gave it. The lab proves the point with a second starting stock. Give the racy model two units and two buyers, and run both invariants:
- No oversell: stock is never negative and sold is at most the starting stock.
- Conserved: stock plus sold equals the starting stock, and stock is not negative.
With two units, both buyers read 2 and both write 1. The shelf says 1 unit left and two units are gone. Sold is 2, which is not more than the 2 that existed, so no oversell holds on every state. Conserved does not: 1 plus 2 is 3. The bug is the same, and the weaker invariant misses it.
The TLA+ file in the lab, models/ReserveStock.tla, states NoOversell == sold <= InitialStock. That is the weaker form. With the constants its own comment suggests (two buyers and one unit) it finds the bug. With two units the Python model, whose no_oversell is the same invariant plus stock >= 0, says it holds, and a reader who ran only that configuration would be reassured wrongly. This is the common failure of model checking, not an accident of this file: people check the properties they thought of. The AWS paper makes the matching point when it lists a lock manager where TLA+ gave more confidence but did not find a liveness bug, because the team had not checked liveness.
A good invariant is the reason the system works, written as a statement about state. For stock it is conservation: every unit is either on the shelf or on an order. For Ferrowave it is the same shape: for every payout, the debits recorded in the ledger sum to the amount once, or to zero while it is still pending. Writing that sentence is half the value, and teams that write specifications often report that this is when they find the first doubt.
Reading the same model as TLA+
TLA+ is Leslie Lamport’s language for describing systems as a set of states and steps in the same way, using simple mathematics, and it comes with two tools: TLC, a model checker, and TLAPS, a proof system. Lamport’s own page describes it as a language for modelling programs and systems, especially concurrent and distributed ones. The checker in the lab is a small stand-in for TLC. The spec in models/ReserveStock.tla is the same model written in TLA+. TLC was not run for this lab: it needs Java, which the lab does not use, and the only checker run is the Python one. Read the file side by side with reserve_stock.py, and the mapping is direct.
| TLA+ | In the Python model |
|---|---|
CONSTANTS Buyers, InitialStock |
the number of buyers and INITIAL_STOCK |
VARIABLES stock, sold, pc, seen |
the state tuple: stock, sold, and each buyer’s phase and the count it read |
Init == ... |
initial() |
Read(b), Write(b) |
the two branches of _buyer_steps for the racy version |
Next == \E b \in Buyers : Read(b) \/ Write(b) |
next_states: for each buyer, each step it can take |
NoOversell == sold <= InitialStock |
invariant |
Spec == Init /\ [][Next]_<<...>> |
the search: start at Init, apply Next forever |
Three differences are worth noticing. First, a primed name such as stock' is the value in the next state, so Write(b) reads like a rule: if this buyer has read, then these things hold after the step and these things stay the same. UNCHANGED lists what a step leaves alone. In Python you build a new tuple. Second, Buyers is a set, so asking TLC for three buyers means changing one line of configuration and not the model, and TLC can treat the buyers as interchangeable to cut the search. Third, TLA+ can say more than the Python checker can: it can state liveness properties, such as every request eventually gets an answer, and it can express that one design correctly refines another. The Python checker looks only at states. AWS’s lock manager is the reminder that a safety-only check misses a stuck system.
If you want to run it, install the TLA+ tools, make a model with Buyers as {"A", "B"} and InitialStock as 1, name NoOversell as an invariant, and TLC reports the violation with a trace. The file’s own comment gives the trace it expects, the same one as above. That is the file’s claim, not something this chapter ran.
Where this has paid, and what it cost
The best-documented case is in Newcombe and colleagues’ account of the use of formal methods at Amazon Web Services. The paper reports that TLA+ either found bugs the team was sure it would not have found otherwise or gave enough confidence to make an aggressive optimisation safely. The numbers in its table cover six components and are modest on purpose: specifications of 102 to 939 lines, and in the six components tabulated, 0 to 3 bugs found (the lock manager found none). The bug that made the case at DynamoDB was in the replication and fault-tolerance design, and needed a trace of 35 steps: a particular sequence of failures and recoveries interleaved with other work. It had passed design review, code review and extensive testing. They report that engineers from entry level to principal learned TLA+ in two to three weeks.
Those are claims by the authors about their own work. Read them with that in mind. They fit what the model above shows. Thirty-five steps is far beyond what a person imagines and also beyond what a random test reaches, but it is a short path for a breadth-first search over a few million states.
The same paper is honest about the gap. Asked how they know the code implements the verified design, the authors answer that they do not, and explain what they get anyway: a correct design, a better understanding of it, and sharper assertions in the code. That gap is the main limit of the technique, and two later papers in the reading list work on it from different sides.
- MongoDB’s engineers (Davis and colleagues) tried checking that the real server follows its TLA+ replication spec by logging the code’s behaviour and replaying it against the spec. They found it impractical for a highly abstract spec, and found that generating test cases from a spec worked well for a more concrete algorithm. The lesson is about the size of the gap between model and code.
- Amazon S3’s storage node team (Bornholt and colleagues) wrote the specification as executable reference models, in the same language as the code, and checked them with property-based testing, stateful tests and model checking. The paper reports that this kept 16 issues out of production. That is Hypothesis’s idea with a different spec.
That second route is worth trying on a small scale, and the lab does so.
Hypothesis meets the model
The chapter on property-based testing said that a Hypothesis state machine runs one operation at a time, so it cannot see a race between two threads. That stays true of the real inventory.py. It does not hold for the model, because in the model a read and a write are separate steps. Let Hypothesis choose which buyer moves next, as a list such as [0, 1, 0, 1], apply each move to the model, and check the invariant after every move. The lab does it in about 20 lines. Hypothesis finds a failing schedule and shrinks it to [0, 1, 0, 1]: A, B, A, B, the same trace the checker found.
What does that comparison teach? At this size the two are equal, since 4 of 6 orderings fail and any sampler finds one. They separate as the model grows. The checker’s pass is exhaustive and its trace is the shortest. Hypothesis’s pass is a sample, but it needs no checker, runs inside the test suite you already have, and scales to models that are too big to enumerate. Teams use both: the checker where the model is small and the stakes are high, and the sampler where it is not.
Proofs: the far end of the scale
A model checker covers a bounded model. A proof covers every size and every run. With TLAPS, or a proof assistant such as Coq or Isabelle, you write the invariant and a chain of reasoning that a machine checks line by line. When it accepts, the rule holds for any number of buyers, any amount of stock, any length of history.
The price is large. Proofs take specialist skill, they take months for a protocol where a model check takes weeks, and they must be redone when the design changes. That is why they appear in a few places: compilers, operating-system kernels and cryptographic routines, where the thing is small and stable and one bug is catastrophic.
Even there, the proof covers only what it covers. Yang and colleagues built Csmith, a random generator of C programs, and used it to find more than 325 bugs in mainstream C compilers. They also tested CompCert, a compiler whose main parts were proved correct. They found bugs in the parts of CompCert that were not proved, the front end, and the developer extended the verified part in response. The paper’s point is about the boundary: a proof guards what is inside it, and the unproved edge, such as a parser, carries the risk. It is also a result about testing, because the most effective tool in the study was a test generator.
Where each tool pays
Use the cheapest tool that can answer the question you have.
| Question | Tool | Cost |
|---|---|---|
| Does this function give the right answer for these inputs? | Example tests | Minutes |
| Does this rule hold for every input I can generate? | Property tests | Hours |
| Does this code hold up under a sequence of calls, or a timeout, or a late reply? | Stateful tests, fault injection, simulation (the earlier chapters) | Days |
| Can any interleaving of a design break this invariant? | Model checking (TLA+ and TLC, or a small checker like the lab’s) | Weeks, for a few hundred lines |
| Does this rule hold for every size and every run? | A proof | Months, by specialists |
Formal methods pay when four things are true together:
- The bug is in the design. Concurrency, retries, failure and recovery, ordering, agreement between nodes. Not arithmetic, not a UI, not a mapping from one JSON shape to another.
- The failing sequence is long and rare. If a barrier and a loop find it, use them.
- The cost of one escape is high. Lost money, lost data, a regulator. The Ferrowave ledger qualifies. The marketplace’s search ranking does not.
- The core is small and changes slowly. A model of a few hundred lines can be kept in step with a protocol. A model of an entire service cannot be kept in step with anything.
They do not pay for most code. A pricing function with a rounding rule is better served by a property test and a mutation run. A model of something no one will update ages into a false comfort.
Three more warnings, from the model above. The model may be wrong, because it is a copy of the system in somebody’s head, and the checker will certify a wrong copy. The invariant may be too weak, as the two-unit run shows. And a clean check proves nothing about the code. Treat a model as a design review that can run, and keep the code honest with the tests that run against it.
You will run the lab’s checker on the reserve-stock model, generalise the model to any number of buyers, see the state count explode, find a bug that a weak invariant misses, check a compare-and-set fix, and let Hypothesis find the same trace by sampling schedules. TLC is not run: the lab has no Java, and models/ReserveStock.tla is for reading. Work from labs/testing. Nothing here starts a server, so no port is used.
1. Run the checker on the model that ships.
cd labs/testing
.venv/bin/python -m models.reserve_stockatomic: 4 states visited, invariant holds
racy: 12 states visited, INVARIANT BROKEN
init -> stock=1 sold=0 A=idle B=idle
A reads the count -> stock=1 sold=0 A=read B=idle
B reads the count -> stock=1 sold=0 A=read B=read
A writes 0 -> stock=0 sold=1 A=done B=read
B writes 0 -> stock=0 sold=2 A=done B=doneThe atomic version has 4 states and never breaks. The racy version breaks in 4 steps, and the counterexample is the shortest one, because the search is breadth-first. The 12 is the number of states seen when the checker stopped at the violation.
Open models/reserve_stock.py and models/ReserveStock.tla side by side, and find each row of the mapping table in the chapter. Nothing else runs for the TLA+ file.
2. Generalise: any number of buyers, any stock, a third version. Create models/scale.py. It adds cas, a read followed by a write that succeeds only if the count is unchanged, and otherwise reads again (the shape of UPDATE ... WHERE on_hand = ? with the value you read):
"""The reserve-stock model for n buyers and any starting stock, in three versions.
atomic one step: if stock >= 1, take it (Database.take_stock)
racy read the count, then write count - 1 in a second step
cas read the count, then write only if the count is unchanged (else retry)
State: (stock, sold, buyers). A buyer is ("idle",), ("read", seen) or ("done",).
"""
import sys
from models.checker import check
IDLE, DONE = ("idle",), ("done",)
def model(n, stock, mode):
initial = (stock, 0, (IDLE,) * n)
def next_states(state):
s, sold, buyers = state
for i, b in enumerate(buyers):
def put(new_s, new_sold, new_b):
return (new_s, new_sold, buyers[:i] + (new_b,) + buyers[i + 1:])
name = chr(ord("A") + i)
if b == IDLE:
if mode == "atomic":
if s >= 1:
yield f"{name} takes the unit", put(s - 1, sold + 1, DONE)
else:
yield f"{name} finds none", put(s, sold, DONE)
else:
yield f"{name} reads {s}", put(s, sold, ("read", s))
elif b[0] == "read":
seen = b[1]
if seen < 1:
yield f"{name} sees none", put(s, sold, DONE)
elif mode == "racy":
yield f"{name} writes {seen - 1}", put(seen - 1, sold + 1, DONE)
elif s == seen: # cas: the count is what we read
yield f"{name} writes {seen - 1}", put(seen - 1, sold + 1, DONE)
else: # cas: someone changed it; read again
yield f"{name} retries", put(s, sold, IDLE)
return initial, next_states
def no_oversell(initial_stock):
return lambda st: st[0] >= 0 and st[1] <= initial_stock
def conserved(initial_stock):
return lambda st: st[0] >= 0 and st[0] + st[1] == initial_stock
if __name__ == "__main__":
n, stock = int(sys.argv[1]), int(sys.argv[2])
for mode in ("atomic", "racy", "cas"):
init, nxt = model(n, stock, mode)
for label, inv in (("no oversell", no_oversell(stock)), ("conserved", conserved(stock))):
trace, seen = check(init, nxt, inv)
verdict = "holds" if trace is None else f"BROKEN in {len(trace) - 1} steps"
print(f"{mode:7} {label:12} {verdict:20} ({seen} states visited)")Run two buyers and one unit:
.venv/bin/python -m models.scale 2 1atomic no oversell holds (4 states visited)
atomic conserved holds (4 states visited)
racy no oversell BROKEN in 4 steps (12 states visited)
racy conserved BROKEN in 4 steps (12 states visited)
cas no oversell holds (11 states visited)
cas conserved holds (11 states visited)Compare-and-set is safe at this size: a buyer whose count went stale retries instead of writing.
3. A weak invariant misses the bug. Two units, two buyers:
.venv/bin/python -m models.scale 2 2atomic no oversell holds (4 states visited)
atomic conserved holds (4 states visited)
racy no oversell holds (12 states visited)
racy conserved BROKEN in 4 steps (12 states visited)
cas no oversell holds (11 states visited)
cas conserved holds (11 states visited)The racy model has the same bug, and no oversell says it holds: both buyers write 1, sold is 2 and the shelf shows 1, which breaks conservation but not the weaker rule. This is the invariant ReserveStock.tla states. Run .venv/bin/python -m models.scale 3 2 as well: with three buyers the weak invariant breaks too (in 6 steps), while conserved breaks in 4.
4. Count the states. Create models/growth.py:
"""How many states does each version have as buyers are added? (stock 1)"""
import time
from models.checker import check
from models.scale import model
print("buyers atomic racy cas seconds")
for n in range(2, 8):
row, t0 = [], time.time()
for mode in ("atomic", "racy", "cas"):
init, nxt = model(n, 1, mode)
_, seen = check(init, nxt, lambda state: True) # never fails: visit everything
row.append(seen)
print(f"{n:>6} {row[0]:>7} {row[1]:>9} {row[2]:>9} {time.time() - t0:.2f}").venv/bin/python -m models.growthbuyers atomic racy cas seconds
2 4 12 11 0.00
3 8 56 45 0.00
4 16 272 191 0.00
5 32 1312 813 0.01
6 64 6208 3431 0.03
7 128 28800 14325 0.18The atomic model doubles per buyer. The racy and compare-and-set models grow about 4.7-fold and 4.2-fold per buyer. The seconds column is from one machine; yours differs, but the counts are the same on any machine.
5. Let Hypothesis choose the schedule. Create tests/test_reserve_model.py:
"""Hypothesis picks the schedule; the model says what each step does."""
import pytest
from hypothesis import given, strategies as st
from models.scale import conserved, model
def run(schedule, mode, buyers=2, stock=1):
state, next_states = model(buyers, stock, mode)
invariant = conserved(stock)
for who in schedule:
prefix = chr(ord("A") + who) + " "
moves = [s for name, s in next_states(state) if name.startswith(prefix)]
if moves: # a buyer that is done has no step: skip it
state = moves[0]
assert invariant(state), f"invariant broken after schedule {schedule}"
schedules = st.lists(st.integers(min_value=0, max_value=1), max_size=12)
@given(schedules)
def test_atomic_holds_under_any_schedule(schedule):
run(schedule, "atomic")
@pytest.mark.xfail(strict=True, reason="the racy version loses the invariant")
@given(schedules)
def test_racy_breaks_under_some_schedule(schedule):
run(schedule, "racy").venv/bin/pytest tests/test_reserve_model.py -p no:randomly -q.x [100%]
...
1 passed, 1 xfailed(A warning about urllib3 and LibreSSL may appear above the summary on macOS; it is unrelated.) The first test passes: no schedule of the atomic model breaks the rule. The second is expected to fail and does, which xfail(strict=True) turns into a pass. Remove the xfail line and the import pytest line, run it again, and Hypothesis reports schedule=[0, 1, 0, 1]: A, B, A, B. It shrank a long random schedule to the checker’s trace.
6. Put the lab back, after the break below. Later chapters count files from the starter state, so when you have finished the break, delete what you added:
rm models/scale.py models/growth.py tests/test_reserve_model.py
rm -rf .hypothesis
git status --short models testsgit status prints nothing for those folders when the lab is back to its starting state.Break it. Before step 6, in models/scale.py change the line elif s == seen: # cas: the count is what we read to elif True: # cas: the count is what we read. The write no longer checks that the count is unchanged. Run .venv/bin/python -m models.scale 2 1. The cas rows now say BROKEN in 4 steps (12 states visited), because the version has become the racy one. You have seen what the checker is for: a one-line change that no example test would flag, caught because the model keeps every interleaving. Then ask what the check did not say: the model of a fix passed, and the code could still differ from it.
Magda's team at Ferrowave is about to change how the ledger handles retries after a bank connector timeout. The rule is that a payout is debited exactly once. The change touches a retry, a crash-recovery path and the reconciliation job, and Wiktor says the existing tests pass but he cannot say what sequences they miss. The team has six engineers, the change must ship in six weeks, and a double debit would be a loss for a customer paying salaries. What should the team do?
- PAPER Newcombe et al., Use of Formal Methods at Amazon Web Services (2014 report; published as How Amazon Web Services Uses Formal Methods, CACM, 2015) Chris Newcombe, Tim Rath, Fan Zhang, Bogdan Munteanu, Marc Brooker, Michael Deardeuff, 2014
The source for the numbers in this chapter: 10 systems, specifications of 102 to 939 lines, a 35-step trace, and the honest limit that the code is not verified. This is the 2014 report hosted by Lamport; the CACM version (doi 10.1145/2699417) is behind a publisher that blocks automated fetches, so check the CACM text for the final wording. Read: The introduction, the table of systems, the DynamoDB section and the answer to how they know the code implements the design; skip the survey of other tools.
- DOC Wayne, Learn TLA+ Hillel Wayne
A free guide that teaches TLA+ from the first operator. Read the core section until you can write a spec like ReserveStock.tla yourself, then stop; the advanced topics are optional and mostly independent.
- DOC Lamport, The TLA+ home page Leslie Lamport
The author's own page for the language and its tools: the TLC model checker, the TLAPS proof system and the Toolbox. Use it to find the downloads and the video course.
- BOOK Lamport, Specifying Systems (2002), free PDF and errata Leslie Lamport, 2002
The definitive text on TLA+ from its author, free for personal use, with a list of corrections and the book's example specifications. Read: Chapters 1 to 7, which the page says cover most readers' needs (83 pages); skip the rest until you need it.
- PAPER Bornholt et al., Using lightweight formal methods to validate a key-value storage node in Amazon S3 (SOSP, 2021) James Bornholt and eleven others, 2021
Executable specifications checked by property-based tests and model checking, which the paper reports kept 16 issues out of production. The nearest published match to the Hypothesis step in the lab. The page is Amazon's abstract and link to the paper. Read: The overview and the sections on reference models and on property-based testing against them; skip the proof details.
- PAPER Davis, Hirschhorn and Schvimer, eXtreme Modelling in Practice (PVLDB, 2020) A. Jesse Jiryu Davis, Max Hirschhorn, Judah Schvimer, 2020
The honest account of the gap between model and code: one approach was impractical, one worked well, and the paper says why. Read it before promising your manager that the code matches the spec. Read: The abstract and the two case studies: trace-checking MongoDB's replication spec, and generating tests for the Realm Sync algorithm.
- PAPER Yang, Chen, Eide and Regehr, Finding and Understanding Bugs in C Compilers (PLDI, 2011) Xuejun Yang, Yang Chen, Eric Eide, John Regehr, 2011
Over 325 compiler bugs found by random testing, including in the unproved parts of a verified compiler. It shows where a proof stops and a test generator keeps working. This is the authors' preprint; the ACM version blocks automated fetches. Read: The abstract, the introduction and the section on testing CompCert; skip the generator's internals.
All companies and people in these examples are fictional. Any resemblance to a real business or person is unintended.