<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - MemorySanitizer false positive with -O2 or higher"
   href="http://llvm.org/bugs/show_bug.cgi?id=22077">22077</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>MemorySanitizer false positive with -O2 or higher
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.5
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>oliverst@online.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=13616" name="attach_13616" title="preprocessed C source code">attachment 13616</a> <a href="attachment.cgi?id=13616&action=edit" title="preprocessed C source code">[details]</a></span>
preprocessed C source code

This code

#include <string>

void func(const char* s)
{
    if(s== NULL)
    {
    }
}

int main()
{
    func((std::string("const ") + "manager").c_str());
    return 0;
}

generates the following warning when compiled with "-fsanitize=memory
-fsanitize-memory-track-origins -O2". It also happens with -O3, but not with
-O1 or without optimizations.

==13491== WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x7f74e825e04b in main (/home/notroot/trunk/a.out+0x8f04b)
    #1 0x7f74e6dbbec4 in __libc_start_main
/build/buildd/eglibc-2.19/csu/libc-start.c:287
    #2 0x7f74e825da5c in _start (/home/notroot/trunk/a.out+0x8ea5c)

  Uninitialized value was created by an allocation of '' in the stack frame of
function 'main'
    #0 0x7f74e825db60 in main (/home/notroot/trunk/a.out+0x8eb60)

SUMMARY: MemorySanitizer: use-of-uninitialized-value ??:0 main

I am using the official clang 3.5 binaries from llvm.org on ubuntu 14.04.

clang version 3.5.0 (tags/RELEASE_350/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7.3
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.2
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.1
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Candidate multilib: .;@m64
Selected multilib: .;@m64</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>