<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/95367>95367</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Specifying -ftrapv or -fsanitize=undefined at the same time as -fsanitize=memory does not detect some uninitialized variable references
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
yamam
</td>
</tr>
</table>
<pre>
`test.c`
```c
int main(void)
{
int a;
int c = a + 0;
if(c)
{
c++;
}
return 0;
}
```
It is expected that a memory access violation will be detected as follows.
```
$ clang -fsanitize=memory -fPIE -pie test.c
$ ./a.out
==1747352==WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0x5652f3f13413 in main (/tmp/a.out+0xca413) (BuildId: 86494c3488075ddb4a2e0750989d5039f1525021)
#1 0x7f2f0b8471c9 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#2 0x7f2f0b84728a in __libc_start_main csu/../csu/libc-start.c:360:3
#3 0x5652f3e7b2f4 in _start (/tmp/a.out+0x322f4) (BuildId: 86494c3488075ddb4a2e0750989d5039f1525021)
SUMMARY: MemorySanitizer: use-of-uninitialized-value (/tmp/a.out+0xca413) (BuildId: 86494c3488075ddb4a2e0750989d5039f1525021) in main
Exiting
```
However, when I add the -ftrapv or -fsanitize=undefined options, the uninitialized variable access violation is not detected.
```
$ clang -fsanitize=memory -ftrapv -fPIE -pie test.c
$ ./a.out
$ clang -fsanitize=memory -fsanitize=undefined -fPIE -pie test.c
$ ./a.out
```
**Environment Information**
```
$ clang --version
Ubuntu clang version 18.1.3 (1)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
$ uname -r
6.8.0-35-generic
$ head -1 /etc/os-release
PRETTY_NAME="Ubuntu 24.04 LTS"
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VV1v2zYU_T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