The LLVM compiler stack offers a number of sanitizers like the AddressSanitizer, MemorySanitizer, UndefinedBehaviorSanitizer, and others for detecting different coding issues like data races, memory addressing issues, use of uninitialized memory, and more. The newest sanitizer addition to LLVM mainline is TySan as a Type Sanitizer.
Merged today to LLVM Git for next year’s LLVM 20 release is TySan as a sanitizer for type-based aliasing violations.
The Git commit landing the Type Sanitizer explains of this new addition:
“C/C++ have type-based aliasing rules, and LLVM’s optimizer can exploit these given TBAA metadata added by Clang. Roughly, a pointer of given type cannot be used to access an object of a different type (with, of course, certain exceptions). Unfortunately, there’s a lot of code in the wild that violates these rules (e.g. for type punning), and such code often must be built with -fno-strict-aliasing. Performance is often sacrificed as a result. Part of the problem is the difficulty of finding TBAA violations. Hopefully, this sanitizer will help.”
The merge request dates back almost one year exactly and contains more background and discussion on this new LLVM Type Sanitizer for those interested.
The idea for the Type Sanitizer isn’t new but was started back in 2017 by Hal Finkel at Argonne National Laboratory. This slide deck offers more background information as well for the motives of this newest sanitizer.