[clang] [llvm] [Clang] Add __builtin_allow_sanitize_check() (PR #172030)

Marco Elver via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 7 14:15:17 PST 2026


melver wrote:

> I guess maybe I'm not sure about the expected usage. Is the code you're trying to skip over code which performs checks, or code which instruments allocations? We could potentially have separate builtins which would return different values for those cases. The documentation doesn't clearly state which case the builtin is intended for.

It's intended for conditionally executing code that performs explicit checks using the runtime's internal state. For example like so:
```
if (__builtin_allow_sanitize_check("thread")) { // similar for asan, msan 
   __tsan_read8(addr);  // explicit check
}
asm volatile (... inline asm that accesses addr ...);
```
In the Linux kernel more APIs exist to let the sanitizer runtime perform explicit checks given a pointer + size, but we need to skip over them if we're in a context where instrumentation (be implicit or explicit) is disallowed.

So it's really very similar to `__builtin_allow_runtime_check` in spirit, except the runtime here is a known sanitizer and the policy when we're allowed to check is much simpler for now.

If the documentation can be improved, we can certainly do so. Maybe instead of "Conditional Sanitizer Checks .." it should be "Explicit Sanitizer Checks .." with a more concrete example.

https://github.com/llvm/llvm-project/pull/172030


More information about the cfe-commits mailing list