-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Open
Labels
compiler-rt:msanMemory sanitizerMemory sanitizer
Description
The following code when compiled with -O1
or above does not provide any errors even though some parts of x have not been initialized.
#include <stdint.h>
#include <string.h>
int main(int argc, char **argv) {
uint32_t x;
uint32_t y = argc;
memcpy(&x, &y, 1);
return x;
}
The code does give an error when compiled with -O0
==1==WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0x555f7308f65a in main /app/example.cpp:8:5
#1 0x7f3c4fc29d8f (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f) (BuildId: c289da5071a3399de893d2af81d6a30c62646e1e)
#2 0x7f3c4fc29e3f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e3f) (BuildId: c289da5071a3399de893d2af81d6a30c62646e1e)
#3 0x555f72ff52e4 in _start (/app/output.s+0x322e4)
SUMMARY: MemorySanitizer: use-of-uninitialized-value /app/example.cpp:8:5 in main
Exiting
this is all with post 18 trunk(7de82ca)
https://godbolt.org/z/TYePeb5r4
Metadata
Metadata
Assignees
Labels
compiler-rt:msanMemory sanitizerMemory sanitizer