I'm using manjaro linux on x86-64. Memory-sanitizer in clang version 10.0.1 reported a use of uninitialized value error in std::map
, which quite surprised me. Did I do something wrong?
$ cat test.cpp
#include <map>
int main() {
std::map<int, int> test;
test.insert({1,2});
}
$ clang++ -fsanitize=memory test.cpp && ./a.out
==51936==WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0x562889eaad9a (/tmp/build/a.out+0x9fd9a)
#1 0x562889eaae28 (/tmp/build/a.out+0x9fe28)
#2 0x562889eaaba1 (/tmp/build/a.out+0x9fba1)
#3 0x562889eaa51e (/tmp/build/a.out+0x9f51e)
#4 0x562889eaa087 (/tmp/build/a.out+0x9f087)
#5 0x7f418e02b151 (/usr/lib/libc.so.6+0x28151)
#6 0x562889e2b1dd (/tmp/build/a.out+0x201dd)
SUMMARY: MemorySanitizer: use-of-uninitialized-value (/tmp/build/a.out+0x9fd9a)
Exiting
When using MemorySanitizer, all libraries you use must be compiled with MemorySanitizer. Otherwise, there is a risk of false positives. This includes the C++ standard library itself.
You will find instructions for compiling libc++ with MemorySanitizer in the official sanitizers wiki:
https://github.com/google/sanitizers/wiki/MemorySanitizerLibcxxHowTo