<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/138982>138982</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang] lsan is ignored when used ubsan
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
jonathanpoelen
</td>
</tr>
</table>
<pre>
https://godbolt.org/z/dcj4hh73h
With the following code, which has a memory leak:
```cpp
#include <stdio.h>
int main(int argc, char** argv) {
int* a = new int[10];
a[5] = 0;
volatile int b = a[argc];
if (b)
printf("xx\n");
// bool bb = *reinterpret_cast<bool*>(argv); // ubsan ok
// if (bb)
// printf("xx\n");
return 0;
}
```
Compiling with `-fsanitize=address,undefined` does not detect the memory leak, whereas it is detected with `-fsanitize=address` or `-fsanitize=leak` alone.
Furthermore, compiling with `-fsanitize=leak,undefined` gives link errors which are magically fixed by adding `-fsanitize=address` or `-lubsan`:
```sh
/usr/bin/ld: /home/jonathan/rawdisk/test-c09389.o: in function `main':
test.cpp:(.text+0x53): undefined reference to `__ubsan_handle_type_mismatch_v1'
/usr/bin/ld: test.cpp:(.text+0xa7): undefined reference to `__ubsan_handle_pointer_overflow'
/usr/bin/ld: test.cpp:(.text+0xd3): undefined reference to `__ubsan_handle_type_mismatch_v1'
/usr/bin/ld: test.cpp:(.text+0x140): undefined reference to `__ubsan_handle_pointer_overflow'
/usr/bin/ld: test.cpp:(.text+0x16c): undefined reference to `__ubsan_handle_type_mismatch_v1
```
clang version 19.1.7
```
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-pc-linux-gnu/13.3.1
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-pc-linux-gnu/14.2.1
Found candidate GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.3.1
Found candidate GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/14.2.1
Selected GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/14.2.1
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzEVk-P27YT_TTjy8CCROqfDz547eiH37kFejQocmwxS5EGSXm9-fQFJe8mzXYTtEEawIAlcmbee-QbkSIEfbZEW6geoDqsxBQH57cfnRVxEPbiyJBd9U49b4cYLwH4DlgHrDs71TsTM-fPwLpPwDolP5bD0PAB8h3kuz90HDAOhCdnjHvS9ozSKQK2x6dBywEHEVDgSKPzz2hIPKbacyrU-fKTl0t6ZVxbaSZFCHwfotIuG4B_WIK1jTgKbYG16VH4s0wYchAe2A7YLg1dgW0QmgfId4jaxnkYgR_Q0tM8UD0UOVQH4HOMgOqhguowh-T3Qbw6I6I2lBKwn-dS4Az5mor6hMDaHthmfkW8eG3jCVgLjN1uUO0tMJaml4RlPbF3zmC_VAW286RtJH_xFI9ShAh8nyKSJP4BWHsXBfzhpcDUB2HRPc6o97E7l1cy9-HvMEJPcfL2RTg0hy83ZVn2vRsv2qRdfUobDXW-PgVhddSfCPhBKOUpBGD7ySo6aUsK6hyVo4DWRVQUScbZH186YDYHeRIBdUQd7nGkvo1S5-j8m9m5Yp2jMM5SttDuJh8H8qPzsxPlt1XcOf1FwllfKaDR9hHJe-fD3c7CE47irKUw5hlP-kYK-2cUSqXy32du5v1L6_umDcLcUqybggfW9cnrnVHAZ-8MbiRg3UvHAuu8eFI6PALrIoW4lvmGt5vMpXht8TRZGbWzCXTpm2ZBTMFZ6rjU4m0W6RaBPeS3is_O2OHrMqCnE3mykjC6VOd4nMkfB2GVoWN8vtBx1GEUUQ7Ha5Eg3hHwHqho_inoxc0Nc3RX8ifjnv4FqPoVSosy_wVSi1r-sNY33wRphD3jlXxI_io2WZE1X0X9LvyZYsK9tfWxLtcXuTbaTrf12U5pfvAkFI5OkUlR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