ramosian-glider / memory-sanitizer

Automatically exported from code.google.com/p/memory-sanitizer
0 stars 0 forks source link

msan false positive when using std::{cout|cerr|clog}. #88

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Compile with msan and libc++ instrumented by msan following code:
#include <iostream>

int main() {
  const char foo[] = "foo";
  std::cout << foo << std::endl;
  return 0;
}

2. Run it.

What is the expected output?
"foo" in the stdout.

What do you see instead?
==10290== WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x7f85c31a9a92 in std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) /home/y/coding/llvm/libcxx-msan/include/c++/v1/ostream:752:13
    #1 0x7f85c31a7bbf in std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::operator<< <std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*) /home/y/coding/llvm/libcxx-msan/include/c++/v1/ostream:894:12
    #2 0x7f85c31a7792 in main /home/y/coding/msan-tests/main.cc:5:13
    #3 0x7f85c1a46ec4 in __libc_start_main /build/buildd/eglibc-2.19/csu/libc-start.c:287
    #4 0x7f85c31408ee in _start (/home/y/coding/msan-tests/bin/main+0x198ee)

  Uninitialized value was created by an allocation of '__s' in the stack frame of function '_ZNSt3__124__put_character_sequenceIcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_PKS4_m'
    #0 0x7f85c31a8880 in std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) /home/y/coding/llvm/libcxx-msan/include/c++/v1/ostream:746

SUMMARY: MemorySanitizer: use-of-uninitialized-value 
/home/y/coding/llvm/libcxx-msan/include/c++/v1/ostream:752:13 in 
std::__1::basic_ostream<char, std::__1::char_traits<char> >& 
std::__1::__put_character_sequence<char, std::__1::char_traits<char> 
>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, 
unsigned long)
Exiting

What version of the product are you using?
I'm using custom llvm(r233049) and clang(r233053) build, also, I'm linking
with msan-instrumented libc++ (r233012). I attached CMakeLists.txt which 
contains options I use and main.cc files.

Original issue reported on code.google.com by ygorshenin@chromium.org on 26 Mar 2015 at 10:48

Attachments:

GoogleCodeExporter commented 9 years ago
What's interesting, after replacement of cout to printf() everything works fine.

Original comment by ygorshenin@chromium.org on 26 Mar 2015 at 11:35

GoogleCodeExporter commented 9 years ago
Welcome back! :) 
What happens if you try this step-by-step? 
https://code.google.com/p/memory-sanitizer/wiki/LibcxxHowTo

Original comment by konstant...@gmail.com on 26 Mar 2015 at 4:15

GoogleCodeExporter commented 9 years ago
This is exactly what I see when running with _uninstrumented_ libc++.
With _instrumented_ libc++ the test passes.
Please verify that the right library is used at runtime (with -Wl,-rpath or 
LD_LIBRARY_PATH, see the link in #2).

Original comment by euge...@google.com on 26 Mar 2015 at 6:02

GoogleCodeExporter commented 9 years ago
Thank you, eugenis@! It seems that I've used uninstrumented libc++ - after 
rebuilding everything works fine!

Original comment by ygorshenin@chromium.org on 27 Mar 2015 at 9:52

GoogleCodeExporter commented 9 years ago

Original comment by euge...@google.com on 27 Mar 2015 at 2:32

GoogleCodeExporter commented 9 years ago
Adding Project:MemorySanitizer as part of GitHub migration.

Original comment by gli...@google.com on 30 Jul 2015 at 9:22