They detect various classes of bugs via runtime instrumentation:
"Enable AddressSanitizer, a fast memory error detector. Memory access instructions are instrumented to detect out-of-bounds and use-after-free bugs."
"Enable ThreadSanitizer, a fast data race detector. Memory access instructions are instrumented to detect data race bugs."
"Enable LeakSanitizer, a memory leak detector. This option only matters for linking of executables and the executable is linked against a library that overrides malloc and other allocator functions."
"Enable UndefinedBehaviorSanitizer, a fast undefined behavior detector. Various computations are instrumented to detect undefined behavior at runtime."
Note that undefined behavior (
https://en.cppreference.com/w/cpp/language/ub) makes a program incorrect from the compiler's perspective and so GIGO ("garbage in, garbage out") applies... with quite astonishing results sometimes. (My favourite example is when both branches of an
if are executed.)