In the presence of undefined behaviour, compiler optimizations can remove the sanitizer checks that would have detected the undefined behaviour. IIUC this mostly affects ASan and MSan because they are inserted after optimization. UBSan is somewhat more reliable because it inserts non-inlinable calls to sanitizer functions before optimization, and the optimizer usually can’t remove those. But there is still some tragicomedy:
This is undefined behavior so UBSan inserts a check that will report this
error and abort the execution. Because the UBSan check is a side effect in a function assumed to be pure, the check itself is now undefined behavior. In the final program the optimizer removes the undefined UBSan check and substitutes the evaluation of ub() with an arbitrarily chosen value.
Many of zigs checks are inserted as llvm ir before optimization. I’m not sure whether they could be susceptible to the same kinds of problems.