[clang] [TySan] Add initial documentation for Type Sanitizer (PR #123595)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 22 09:50:07 PST 2025
================
@@ -0,0 +1,162 @@
+================
+TypeSanitizer
+================
+
+.. contents::
+ :local:
+
+Introduction
+============
+
+The TypeSanitizer is a detector for strict type aliasing violations. It consists of a compiler
+instrumentation module and a run-time library. C/C++ has type-based aliasing rules, and LLVM
+can exploit these for optimizations given the TBAA metadata Clang emits. In general, a pointer
+of a given type cannot access an object of a different type, with only a few exceptions.
+
+These rules aren't always apparent to users, which leads to code that violates these rules
+(e.g. for type punning). This can lead to optimization passes introducing bugs unless the
+code is build with ``-fno-strict-aliasing``, sacrificing performance.
+
+TypeSanitizer is built to catch when these strict aliasing rules have been violated, helping
+users find where such bugs originate in their code despite the code looking valid at first glance.
+
+As TypeSanitizer is still experimental, it can currently have a large impact on runtime speed,
+memory use, and code size.
+
+How to build
+============
+
+Build LLVM/Clang with `CMake <https://llvm.org/docs/CMake.html>`_ and enable
+the ``compiler-rt`` runtime. An example CMake configuration that will allow
+for the use/testing of TypeSanitizer:
+
+.. code-block:: console
+
+ $ cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang" -DLLVM_ENABLE_RUNTIMES="compiler-rt" <path to source>/llvm
+
+Usage
+=====
+
+Compile and link your program with ``-fsanitize=type`` flag. The
----------------
AaronBallman wrote:
Can the type sanitizer be enabled along with other sanitizers, or is it mutually exclusive with some? (If it's mutually exclusive with some, then we should document which ones, otherwise I think the docs are fine as-is.)
https://github.com/llvm/llvm-project/pull/123595
More information about the cfe-commits
mailing list