23.3 · Sanitizers, and bugs that only appear in Release

Some bugs are silent: memory corruption that happens to work, races that only lose once in a thousand runs, checks that exist only in debug builds. Sanitizers and a clear idea of what each build mode removes turn those into reproducible failures.

Mental model. Make the invisible bug loud: instrument the build so the bad access, the race or the broken invariant fails immediately and at the cause.

Sanitizers

Address, undefined-behaviour and thread tools, and the checkers built into the OS.

  1. What do the Address, Thread and Undefined Behavior sanitizers catch, what do they cost, and when do you use them in Swift code? 23.3.1 · L5
    Sanitizers instrument your build so that certain bugs are detected at the moment they happen, with a report naming both the access and the allocation or other…

Debug versus Release

What optimisation removes, and how to debug what only fails in Release.

  1. Why do some bugs appear only in Release builds, how do assert, precondition and fatalError differ, and how do you debug an optimised build? 23.3.2 · L5
    A Release build changes your program in ways a Debug build does not. The optimiser reorders, inlines and removes code, so a race or an uninitialised value that…

More in Debugging & Instruments