Open
Description
test.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"