[llvm-bugs] [Bug 39824] New: False positive error in memory sanitizer

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Nov 28 07:25:35 PST 2018


            Bug ID: 39824
           Summary: False positive error in memory sanitizer
           Product: clang
           Version: 7.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Tooling
          Assignee: unassignedclangbugs at nondot.org
          Reporter: gael.guennebaud at gmail.com
                CC: llvm-bugs at lists.llvm.org

The following self-contained example trigger an error with memory sanitizer:

#include <iostream>

struct Vec {
  const float* data() const {return 0;}

struct myevaluator3 { ~myevaluator3() {} };

struct myevaluator2 : myevaluator3 {
  myevaluator2(const Vec& v) : m(v.data()) {}
  const float * m;

struct myevaluator : myevaluator2 {  
  myevaluator(const Vec& m) : myevaluator2(m) {}

float foo(const Vec&,int) {
  Vec w;
  myevaluator e(w);
  return 0;

int main() {
  Vec v;
  float x = foo(v,0);
  std::cout << x;

Compiling without any optimization, i.e.,

$ clang++-7  bug.cpp -fsanitize=memory && ./a.out

gives me:

Uninitialized bytes in __interceptor_memcmp at offset 244 inside
[0x7ffeeaa581c0, 256)
==10014==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x7f2b3838ce2b in std::ctype<char>::_M_widen_init() const
    #1 0x7f2b383e8df7 in std::ostream& std::ostream::_M_insert<double>(double)
    #2 0x49445c in main (a.out+0x49445c)
    #3 0x7f2b37323b96 in __libc_start_main
    #4 0x41b4d9 in _start (a.out+0x41b4d9)

This is the most reduced test case I managed to get. For instance any of the
following change will remove the reported error:
- remove the destructor ~myevaluator3() {}
- reduce the hierarchy of myevaluator
- change the prototype of foo to: float foo(const Vec&) or float foo(Vec,int)
- removing std::cout << x;
- ...

The reported error also goes away if compiling with -O1 or higher.

I hope I did not reported a false negative ;)

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20181128/27ea1fc6/attachment.html>

More information about the llvm-bugs mailing list