<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/83566>83566</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Support] Bugprone usage of __has_feature(address_sanitizer) in Allocator
</td>
</tr>
<tr>
<th>Labels</th>
<td>
bug,
mlir:core,
llvm:support
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Dinistro
</td>
</tr>
</table>
<pre>
tl;dr:
`llvm/Support/Allocator.h` transitively uses `__has_feature(address_sanitizer)` to decide if it uses `__msan_*` and `__asan_*` markers and if it should allocate a red zone. This is very problematic when this header is pulled into an LLVM compilation unit but is also made available through some LLVM template to downstream users.
**Extended bug explanation**
We observed an ASAN crash in the following setup:
We build LLVM + MLIR without sanitizers enabled, but have a downstream project that is build with ASAN. Due to relying on MLIR's `StorageUniquer`, which is a templated implementation in a header, we pull in a copy of `BumpPtrAllocatorImpl::Allocate`. This function changes behavior, depending on ASAN being enabled or not:
https://github.com/llvm/llvm-project/blob/0e9a102129c07d31dccec06cb45f6e2a74c6e590/llvm/include/llvm/Support/Allocator.h#L156-L159
Additionally, this code contains multiple `__msan_*` and `__asan_*` usages.
Unfortunately, other parts of MLIR's `StorageUniquer` are implemented in a `.cpp` file, which result in it being compiled without ASAN. This is problematic, due the a non-ASAN build replacing all `__msan_*` and `__asan_*` function with empty macros.
https://github.com/llvm/llvm-project/blob/2d98d763a8e627b2d1a18a9cdd1c62a4b58be3aa/llvm/include/llvm/Support/Compiler.h#L441-L461
Therefore, some of the poison marking is compiled in, while unpoison markings are omitted. This can therefore lead to ASAN violations that very tricky to hunt down.
CC @ibookstein
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVd1u4zYTfRr6ZhBDomTZuvCFk3wGFsh-KLq77WUwIscSuxSp8sdZ79MXpBTHAYoiBQoECjwczs85Z4boveoN0Z5t7tnmcYUxDNbtH5VRPji76qy87INm1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